Issue#
You delete a pod, or scale down or roll out a deployment, and the old pod never goes away. It stays in Terminating for minutes or hours:
kubectl get pods -n my-app
NAME READY STATUS RESTARTS AGE
web-7d9c6b8f5d-x2k4p 1/1 Terminating 0 3d
Running kubectl delete pod again just hangs, or returns while the pod stays listed.
Cause#
A pod is removed from the API only when both of these are true:
- The kubelet on its node confirms the containers have stopped.
- All finalizers in
metadata.finalizershave been cleared.
Pods usually get stuck for one of these reasons:
- The node is
NotReadyor gone, so the kubelet can never confirm the shutdown. - A finalizer was added by a controller or operator that no longer exists or is failing.
- The container runtime can't stop the container, often because a volume unmount is hung (NFS, iSCSI, CSI driver issues).
Solution#
- Find out why the pod is stuck before you force anything:
POD=web-7d9c6b8f5d-x2k4p
NS=my-app
kubectl get pod "$POD" -n "$NS" -o jsonpath='{.metadata.finalizers}{"\n"}{.spec.nodeName}{"\n"}'
kubectl describe pod "$POD" -n "$NS" | tail -n 20
- Check the node the pod is scheduled on:
NODE=$(kubectl get pod "$POD" -n "$NS" -o jsonpath='{.spec.nodeName}')
kubectl get node "$NODE"
If the node is NotReady but can still be reached, restart the kubelet on it. That often lets the pod finish terminating normally:
sudo systemctl restart kubelet
sudo journalctl -u kubelet --since "10 min ago" | grep -i "$POD"
- If finalizers are listed, and the controller that owns them is gone or you know the cleanup is safe to skip, remove them:
kubectl patch pod "$POD" -n "$NS" --type=merge -p '{"metadata":{"finalizers":null}}'
- If there are no finalizers and the node is dead, force delete the pod object:
kubectl delete pod "$POD" -n "$NS" --grace-period=0 --force
Warning: A force delete only removes the pod from the API. If the node is actually still running, the container may keep running there. For StatefulSets this can lead to two pods with the same identity writing to the same volume. Make sure the node is really down, or drain or remove it first.
- If the node is permanently gone, delete the Node object so its other pods get cleaned up as well:
kubectl delete node "$NODE"
Verify#
The pod should be gone, and any replacement pod should be Running:
kubectl get pods -n "$NS" -o wide
To list any other pods still stuck across the cluster (anything with a deletion timestamp):
kubectl get pods -A -o json \
| jq -r '.items[] | select(.metadata.deletionTimestamp != null) | "\(.metadata.namespace)/\(.metadata.name)"'
An empty result means nothing else is stuck in Terminating.