Operating, scaling and debugging · 6 MIN READ
When a node dies: NotReady, eviction, PodDisruptionBudgets and safe drains
Explain the timeline from a lost node to rescheduled pods, protect planned maintenance with a PodDisruptionBudget, drain a node safely, and spread replicas so that one node or zone cannot take a service down.
Nodes fail: a kernel panic, a lost network link, a cloud instance retired underneath you. Kubernetes recovers by itself, but after deliberate delays and only for pods that a controller owns. Planned maintenance takes a different path, the Eviction API, and that is where PodDisruptionBudgets decide how many pods may go at once.
kubernetes · A MAP OF THE IDEA
- Node misses heartbeats: NotReady
- Taints added, pods not ready
- Evicted after tolerationSeconds
- Controller creates replacements
Useful when
- Controller-owned pods recover from node loss without a human.
- PodDisruptionBudgets keep drains and upgrades within a safe pace.
Watch out
- Default failover takes about six minutes, and StatefulSet pods wait longer.
- A budget that allows no disruption blocks every drain.
Implementation & operation cost: Spare capacity of at least one node, replicas spread over nodes and zones, and a PodDisruptionBudget per service.
From missed heartbeats to NotReady
Each kubelet renews a Lease in the kube-node-lease namespace every 10 seconds as its heartbeat. The node lifecycle controller in kube-controller-manager checks every 5 seconds; when a node has not reported for the node monitor grace period, 50 seconds by default, it sets the node's Ready condition to Unknown with "Kubelet stopped posting node status", which kubectl shows as NotReady. It taints the node with node.kubernetes.io/unreachable twice: effect NoSchedule, so nothing new lands there, and effect NoExecute, which starts the eviction clock. It also marks the node's pods as not ready, so EndpointSlices drop them and Services stop routing to them. The control plane cannot tell a dead node from a network partition: the containers may still be running, and writing.
Taint-based eviction and the 300-second default
The DefaultTolerationSeconds admission plugin gives every pod two tolerations, for node.kubernetes.io/not-ready and node.kubernetes.io/unreachable with effect NoExecute and tolerationSeconds: 300. So pods stay bound to a lost node for five minutes in case it comes back; then the taint eviction controller deletes them. The deletion cannot complete without the kubelet, so on a real cluster the old pod shows Terminating until the node returns or its Node object is deleted. A ReplicaSet does not count terminating pods and creates a replacement at once. A StatefulSet waits, because two pods with one identity could corrupt data; once you know the machine is off, the node.kubernetes.io/out-of-service taint releases its pods and volumes. A bare pod is simply gone. Shorter tolerationSeconds in a pod template give faster failover. The GopherForge lab evicts after 30 seconds; cluster config eviction=60s changes that.
Voluntary disruptions and PodDisruptionBudgets
Draining a node for an upgrade, the cluster autoscaler removing a node, or rotating a node pool are voluntary disruptions. They evict pods through the Eviction API, which checks every PodDisruptionBudget that selects the pod. A PDB sets minAvailable or maxUnavailable, as a count or a percentage, and its status shows how many disruptions are allowed now. When an eviction would break the budget, the API refuses with 429 and "Cannot evict pod as it would violate the pod's disruption budget", and the caller retries later. A PDB does not protect against node failures, kubectl delete pod or a Deployment rollout, which has its own maxUnavailable. Two traps: minAvailable equal to the replica count, or maxUnavailable: 0, blocks every drain forever, and pods that are already unhealthy can block a drain unless unhealthyPodEvictionPolicy: AlwaysAllow lets them go.
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web
spec:
maxUnavailable: 1
unhealthyPodEvictionPolicy: AlwaysAllow
selector:
matchLabels:
app: webmaxUnavailable: 1 keeps working when the Deployment is scaled, unlike a fixed minAvailable that can end up equal to the replica count. kubectl get pdb shows MAX UNAVAILABLE 1 and ALLOWED DISRUPTIONS 1 while all pods are healthy. AlwaysAllow lets a drain evict pods that are running but not ready, which lose nothing by moving; the default, IfHealthyBudget, evicts them only while the budget is satisfied.
Cordon, drain and uncordon
kubectl cordon marks a node unschedulable: its STATUS becomes Ready,SchedulingDisabled and running pods stay. kubectl drain cordons the node and evicts every pod, honouring PodDisruptionBudgets and each pod's grace period, and retries refused evictions every 5 seconds. It stops without --ignore-daemonsets when DaemonSet pods are present, because their controller would put them straight back; --delete-emptydir-data accepts that emptyDir contents are lost; --force is needed for pods without a controller, which nothing will recreate. After maintenance, kubectl uncordon makes the node schedulable again. Kubernetes never moves running pods back by itself, so a recovered node fills up only as new pods are created; the descheduler project can rebalance.
kubectl cordon kind-worker2
kubectl drain kind-worker2 --ignore-daemonsets --delete-emptydir-data --timeout=120s
kubectl get nodes
kubectl uncordon kind-worker2Without --timeout, drain waits as long as a budget blocks it, which is how a cluster upgrade hangs at 3 a.m. With a timeout it fails, the node stays cordoned until someone looks, and the evictions it completed stay done. get nodes shows the drained node as Ready,SchedulingDisabled until uncordon.
Spread replicas across nodes and zones
Three replicas on one node fail together. topologySpreadConstraints keep the number of matching pods per topology domain within maxSkew of each other: topologyKey kubernetes.io/hostname spreads across nodes, topology.kubernetes.io/zone across zones. whenUnsatisfiable: DoNotSchedule is a hard rule that leaves a pod Pending; ScheduleAnyway only prefers. By default node taints are ignored when counting, so a tainted control-plane node or a cordoned node counts as an empty domain and can block a hard rule; nodeTaintsPolicy: Honor leaves such nodes out. matchLabelKeys with pod-template-hash computes the spread per ReplicaSet, so the new pods of a rollout are spread too. Spreading happens only at scheduling time; Kubernetes itself never moves pods later when the balance drifts.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
tolerations:
- key: node.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
tolerationSeconds: 60
- key: node.kubernetes.io/not-ready
operator: Exists
effect: NoExecute
tolerationSeconds: 60
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Honor
matchLabelKeys:
- pod-template-hash
labelSelector:
matchLabels:
app: web
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: web
containers:
- name: web
image: gopherforge/web:v2The hard hostname rule puts the three replicas on three different workers, and the soft zone rule prefers different zones. The two tolerations replace the 300-second defaults, so pods leave an unreachable node about 110 seconds after its last heartbeat: 50 seconds of grace plus 60. The price is that a network blip of that length now moves every pod off the node.
Try it in the lab terminal
Start a cluster with three workers and run three replicas, one per node. Fail one node and watch it turn NotReady, its pod lose readiness, and a replacement appear after the lab's eviction delay. Then bring the node back, protect the Deployment with a PodDisruptionBudget that keeps two pods available, and drain another node to see the budget pace the evictions.
cluster create --workers 3
kubectl create deployment web --image=gopherforge/web:v2 --replicas=3
kubectl rollout status deploy/web
kubectl get pods -o wide
cluster node fail kind-worker
cluster tick 15s
kubectl get nodes
kubectl get pods -o wide
cluster tick 30s
kubectl get pods -o wide
cluster node recover kind-worker
cat > pdb.yaml <<'EOF'
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web
spec:
minAvailable: 2
selector:
matchLabels:
app: web
EOF
kubectl apply -f pdb.yaml
kubectl drain kind-worker3 --ignore-daemonsets
kubectl get pods -o wide
kubectl uncordon kind-worker3The pods start one per worker. The lab marks a failed node NotReady at once instead of after 50 seconds, so fifteen seconds later kind-worker is NotReady and its pod shows 0/1 Running: still bound, but out of the Service. After the lab's 30-second eviction delay a replacement web-<hash>-<id> runs on kind-worker3; on a real cluster the old pod would linger as Terminating. Recovering kind-worker moves nothing back. The drain evicts one pod from kind-worker3, then prints "Cannot evict pod as it would violate the pod's disruption budget" and retries until the replacement is Ready; both new pods land on the empty kind-worker.
TAKE THIS WITH YOU
A lost node is tainted after about 50 seconds and its pods are evicted after their 300-second tolerations; only controller-owned pods come back. Planned drains go through the Eviction API, where a PodDisruptionBudget keeps enough replicas running.
Check your understanding
A worker node loses power. Its Deployment pods are replaced about six minutes later, not at once. What sets most of that delay?
Go to the source
Progress stays in this browser. No account needed.