Sub topic 18
Troubleshooting Pending pods and stuck drains
This chapter assumes you know Deployments, labels, and kubectl describe. It also assumes you have read the earlier chapters on skew, whenUnsatisfiable, and PodDisruptionBudgets (PDBs). Two symptoms cover most problems with these features: a pod stuck in Pending, and a kubectl drain that never finishes.
Diagnosing a Pending pod
Start with the pod's events. The scheduler records why it rejected each node.
kubectl describe pod <pod-name>A spread failure looks like this:
0/6 nodes are available: 2 node(s) didn't match pod topology spread constraints,
4 node(s) had untolerated taint.The phrase "didn't match pod topology spread constraints" means placing the pod on those nodes would push skew above maxSkew. Work through these checks in order:
- Count the matching pods per domain. Use the same selector as the constraint's
labelSelector. - Confirm every node has the
topologyKeylabel. A node without it cannot take the pod at all. - Check whether taints or node affinity exclude nodes. Excluded nodes are not counted as domains by default, so the remaining domains may be fewer than you expect.
- Check
minDomains. If fewer domains exist thanminDomains, the global minimum is treated as 0. - Check
matchLabelKeys. During a rolling update, old pods can still sit in a zone that new pods cannot use.
kubectl get pods -l app=web -o wide
kubectl get nodes -L topology.kubernetes.io/zoneDiagnosing a stuck drain
A drain that hangs usually repeats this message:
error when evicting pods/"web-abc" -n default (will retry after 5s):
Cannot evict pod as it would violate the pod's disruption budget.Inspect the budget:
kubectl get pdb -A
kubectl get pdb web-pdb -o jsonpath='{.status.disruptionsAllowed}{"\n"}'If disruptionsAllowed is 0, the Eviction API refuses every request for those pods. Common causes are in the table below.
| Cause | Fix |
|---|---|
| `minAvailable` equals the replica count | Lower it, or use `maxUnavailable: 1` |
| Some replicas are already not Ready | Fix them, or set `unhealthyPodEvictionPolicy: AlwaysAllow` |
| The only replica runs on the node being drained | Run at least two replicas |
| The selector matches pods from several workloads | Narrow the selector |
| Replacement pods are Pending because of spread constraints | Resolve the Pending pods first |
The last row shows how the two features interact. A drain evicts a pod, the replacement cannot be scheduled, and the budget then allows no further evictions.
Exercise
A drain of node A hangs. kubectl get pdb shows ALLOWED DISRUPTIONS of 0 for a Deployment with 3 replicas and minAvailable: 3. What is the problem, and what is the smallest safe change?
Show answer
The budget requires all 3 replicas to stay available, so no voluntary eviction is ever allowed. Change it to maxUnavailable: 1 (or minAvailable: 2). That permits one pod to be evicted at a time, and the drain proceeds as each replacement becomes Ready.