Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Kubernetes

Kubernetes: Force Delete Stuck Pods in Terminating State Instantly

- 03.02.26 - ErcanOPAK

Pod stuck in “Terminating” state for hours? Kubernetes is waiting for graceful shutdown that will never complete. Force delete it properly.

The Problem:

# Pod stuck forever
kubectl get pods
NAME                 STATUS        AGE
stuck-pod-abc123     Terminating   3h

# Normal delete doesn't work
kubectl delete pod stuck-pod-abc123
# Still shows Terminating...

Why Pods Get Stuck:

When deleting a pod:
1. Kubernetes sends SIGTERM to container
2. Waits 30 seconds (terminationGracePeriodSeconds)
3. If still alive, sends SIGKILL

Pod gets stuck when:
- Node is unreachable (network issue)
- Finalizer preventing deletion
- Volume unmount fails
- Container ignoring SIGTERM

The Nuclear Option – Force Delete:

kubectl delete pod stuck-pod-abc123 --grace-period=0 --force

# Explanation:
# --grace-period=0  : Skip graceful shutdown
# --force           : Delete immediately from etcd

Pod disappears instantly!

Better: Check Why It’s Stuck First

# See what's preventing deletion
kubectl describe pod stuck-pod-abc123

# Look for:
# - Finalizers: [...list...]
# - Events: Warning messages
# - Node: NotReady status

# Common culprits:
# 1. Finalizer not removed
# 2. PersistentVolumeClaim stuck detaching
# 3. Node disappeared

Remove Finalizers Manually:

# Check finalizers
kubectl get pod stuck-pod-abc123 -o yaml | grep -A5 finalizers

# Output:
# finalizers:
# - kubernetes.io/pvc-protection

# Remove finalizers
kubectl patch pod stuck-pod-abc123 -p '{"metadata":{"finalizers":null}}'

# Pod deletes immediately

Force Delete All Terminating Pods:

# Find all stuck pods
kubectl get pods --field-selector=status.phase=Terminating

# Delete them all
kubectl delete pods --field-selector=status.phase=Terminating \
  --grace-period=0 --force

# Or with namespace
kubectl delete pods -n my-namespace \
  --field-selector=status.phase=Terminating \
  --grace-period=0 --force

Prevent Future Stuck Pods:

# In your deployment YAML
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
      terminationGracePeriodSeconds: 10  # Reduce from 30 to 10
      containers:
      - name: app
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "sleep 5"]
        # App has 5 seconds to cleanup before SIGTERM

Why This Matters:

Scenario: Node fails, 20 pods stuck Terminating

Without force delete:
- Pods stuck for hours (until node timeout)
- New pods can't start (resource quota reached)
- Application downtime

With force delete:
- Pods removed in 30 seconds
- New pods start immediately  
- Application recovers

PersistentVolume Stuck? Delete That Too:

# PVC won't delete because pod using it
kubectl delete pvc my-pvc
# Stuck in Terminating

# Force delete PVC
kubectl patch pvc my-pvc -p '{"metadata":{"finalizers":null}}'

# Or force delete PV
kubectl delete pv my-pv --force --grace-period=0

Node Stuck? Delete It:

# Node shows NotReady, pods stuck
kubectl get nodes
NAME       STATUS     AGE
node-1     NotReady   10h

# Force delete node
kubectl delete node node-1 --force --grace-period=0

# This doesn't delete the actual VM!
# It only removes it from Kubernetes
# Pods on that node will be rescheduled elsewhere

Related posts:

Why Liveness ≠ Readiness Probes

Kubernetes: Use Kustomize for Environment-Specific Configurations

Kubernetes: Advanced Node Scheduling with Taints and Tolerations

Post Views: 2

Post navigation

WordPress: Limit Login Attempts Without Plugins Using .htaccess
Docker: Clean Up Disk Space by Removing Unused Images and Containers

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

March 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« Feb    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (938)
  • How to add default value for Entity Framework migrations for DateTime and Bool (836)
  • Get the First and Last Word from a String or Sentence in SQL (828)
  • How to select distinct rows in a datatable in C# (801)
  • How to make theater mode the default for Youtube (736)
  • Add Constraint to SQL Table to ensure email contains @ (575)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (554)
  • Average of all values in a column that are not zero in SQL (523)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (477)
  • Find numbers with more than two decimal places in SQL (441)

Recent Posts

  • C#: Saving Memory with yield return (Lazy Streams)
  • C#: Why Records are Better Than Classes for Data DTOs
  • C#: Creating Strings Without Memory Pressure with String.Create
  • SQL: Protecting Sensitive Data with Dynamic Data Masking
  • SQL: Writing Readable Queries with Common Table Expressions (CTE)
  • .NET Core: Handling Errors Gracefully with Middleware
  • .NET Core: Mastering Service Lifetimes (A Visual Guide)
  • Git: Surgical Stashing – Don’t Save Everything!
  • Git: Writing Commits That Your Future Self Won’t Hate
  • Ajax: Improving Perceived Speed with Skeleton Screens

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (938)
  • How to add default value for Entity Framework migrations for DateTime and Bool (836)
  • Get the First and Last Word from a String or Sentence in SQL (828)
  • How to select distinct rows in a datatable in C# (801)
  • How to make theater mode the default for Youtube (736)

Recent Posts

  • C#: Saving Memory with yield return (Lazy Streams)
  • C#: Why Records are Better Than Classes for Data DTOs
  • C#: Creating Strings Without Memory Pressure with String.Create
  • SQL: Protecting Sensitive Data with Dynamic Data Masking
  • SQL: Writing Readable Queries with Common Table Expressions (CTE)

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com