Learn Labs
Availability

Node Failure

What happens, and when, after a node dies

A drain is polite: Kubernetes moves pods before the node goes away. A node that loses power gives no warning. node_failure.py stops a worker's container (instantly, like pulling the plug) with 10 requests per second flowing through the Gateway, and logs every change.

./scripts/lab.sh node_failure.py
stopping node lab-worker (runs web-7cb7f4d4cd-rszjq); redis and the Gateway run on ['lab-worker3']
  0s  node Ready=True    taints=-                        in endpoints=True  old pod=Running      new pod=-                  ready=3  errors=0
 45s  node Ready=Unknown taints=unreachable,unreachable  in endpoints=False old pod=Running      new pod=-                  ready=2  errors=7
345s  node Ready=Unknown taints=unreachable,unreachable  in endpoints=False old pod=terminating  new pod=swksc@lab-worker2  ready=2  errors=7
352s  node Ready=Unknown taints=unreachable,unreachable  in endpoints=False old pod=terminating  new pod=swksc@lab-worker2  ready=3  errors=7
after 352s. traffic: 2944 requests, 2937 ok, errors: {'ReadTimeout': 7}, slowest 5.01s
45 s345 snodedeadUnknown, tainted unreachableendpoints7 errorsdead pod removed: no errorsold pod"Running" on a dead nodenew podseconds 0 … 360

0 to 45 seconds: nobody knows

The node is dead, but its kubelet's last report said Ready. Its pod is still in the Service's endpoints, and the Gateway keeps sending it a third of the traffic. Those requests go to an IP where nothing answers: 7 requests hung for 5 seconds each (the client's timeout) before the node was declared unknown.

The node lifecycle controller waits for the node monitor grace period without a heartbeat (the kubelet's Lease) before marking the node Unknown. That took 45 seconds here, in two runs.

45 seconds: out of rotation

When the node became Unknown, two things happened together: the node got the taint node.kubernetes.io/unreachable:NoExecute, and its pods' Ready condition went false, which removed them from the endpoints. From then on, zero errors. But only 2 of 3 pods were serving: the "Running" pod on the dead node still counts toward the Deployment, so nothing replaced it.

345 seconds: evicted and replaced

Every pod gets default tolerations for that taint:

kubectl -n shop get pod web-... -o jsonpath='{.spec.tolerations}'
[{"key":"node.kubernetes.io/not-ready","effect":"NoExecute","tolerationSeconds":300},
{"key":"node.kubernetes.io/unreachable","effect":"NoExecute","tolerationSeconds":300}]

300 seconds after the taint (45 + 300 = 345 s), the pod was evicted: marked for deletion, so the ReplicaSet created a replacement, which the scheduler put in zone-b (the zone-a node was tainted and excluded by nodeTaintsPolicy: Honor). It was ready 7 seconds later.

The old pod stays terminating for as long as the node is unreachable. Nobody can confirm it stopped, so its object isn't deleted until the node comes back (or someone force-deletes it).

Tuning the 5 minutes

tolerations:in the pod spec: evict this pod sooner- key: node.kubernetes.io/unreachableoperator: Existseffect: NoExecutetolerationSeconds: 30- key: node.kubernetes.io/not-readyoperator: Existseffect: NoExecutetolerationSeconds: 30

Shorter tolerations replace pods sooner, but a brief network blip then causes a wave of rescheduling. With enough replicas spread across zones, the default 5 minutes costs capacity, not availability: the surviving pods carry the load. Size replicas so losing a zone still leaves enough.

Lab

  1. Run node_failure.py. Then set tolerationSeconds: 30 on web and run it again. When is the replacement created now?
  2. Stop the node that runs redis-0 and watch /api/visits and the pod. What do you have to do to recover before the node comes back?
  3. Stop a node, then start it again after 60 seconds. What happens to the pods that were on it?

On this page