Sub topic 10
What happens when a Pod or node fails
This chapter assumes you can apply manifests with kubectl and that you know how a StatefulSet names its Pods (web-0, web-1, web-2) and creates one PersistentVolumeClaim (PVC) per Pod (www-web-0, and so on). The examples use the web StatefulSet from earlier chapters.
Pod failure: same name, same disk
A StatefulSet replaces a failed Pod with a Pod that has the same identity. If web-1 crashes or is deleted, the controller creates a new web-1. The new Pod has the same hostname and the same DNS name, web-1.web. It also mounts the same claim, www-web-1.
This differs from a Deployment, where a replacement Pod gets a new random name and a fresh volume.
You can watch it happen:
kubectl delete pod web-1
kubectl get pods -l app=web -w
kubectl get pvc -l app=webThe PVC list is unchanged. Deleting a Pod never deletes its claim, so the data on www-web-1 survives.
Container crashes inside a Pod are handled by the kubelet, which restarts the container according to the Pod's restart policy. The Pod object stays the same, and you see the RESTARTS count increase.
Node failure: the controller waits
Node failure is harder, because the control plane cannot tell a dead node from a network partition. The sequence is:
- The node stops reporting to the API server.
- After the node-monitor grace period, the node controller marks the node
NotReady(orUnknown). - The node controller adds the
node.kubernetes.io/unreachabletaint. Pods tolerate this taint for 300 seconds by default. - When the toleration expires, the Pod is marked for deletion. The kubelet on the dead node cannot confirm the deletion, so the Pod object stays in
Terminatingstate. - The StatefulSet controller does not create a replacement while the old Pod object still exists.
The last step is deliberate. StatefulSets give an at-most-one guarantee: at no time should two Pods with the identity web-1 run at once. If the node is only partitioned, the old web-1 may still be running and writing to its volume. Starting a second web-1 against the same data could corrupt it.
A Deployment makes the opposite trade-off. It starts replacements right away, because its Pods are interchangeable.
Recovering a stuck Pod
You have three ways to resolve a stuck Terminating Pod:
- Bring the node back. The kubelet then finishes the deletion and the controller recreates the Pod.
- Delete the Node object, or let your cloud provider's node controller do it when the machine is confirmed gone. The Pod objects on it are then garbage collected.
- Force-delete the Pod, only after you have confirmed the node is really down.
kubectl get pods -l app=web -o wide
kubectl delete pod web-1 --grace-period=0 --forceVolumes and where the new Pod lands
The replacement web-1 must reach www-web-1. What happens next depends on the storage:
| Storage type | Behavior after rescheduling |
|---|---|
| Network block volume (for example EBS, with `ReadWriteOnce`) | The volume must detach from the dead node before it attaches elsewhere. This can add minutes. The volume is also tied to one zone, so the Pod can only run in that zone. |
| Network file system (NFS, CephFS) | Mounts from any node. Rescheduling is usually quick. |
| Local PersistentVolume | The data lives on the failed node. The Pod stays `Pending` until that node returns. |
If a Pod stays Pending after replacement, run kubectl describe pod web-1 and check the events for volume attach errors or node affinity conflicts.
Ordering during failure
With the default OrderedReady policy, the controller also respects order when a Pod fails. If web-1 is not Running and Ready, the controller does not create or update web-2 until it recovers. A single unhealthy Pod can therefore block a rollout. With podManagementPolicy: Parallel, Pods are replaced independently.
Exercise
A node hosting web-2 loses power. Ten minutes later, kubectl get pods still shows web-2 as Terminating and no replacement exists. Why, and what is the safest way to get a replacement running?
Show answer
The StatefulSet controller will not create a new web-2 while the old Pod object still exists, because it guarantees at most one Pod per identity. The kubelet on the dead node cannot confirm the deletion. First confirm the node is really down (or delete the Node object). Then force-delete the Pod with kubectl delete pod web-2 --grace-period=0 --force, or let the node be removed. The controller then creates web-2 on a healthy node, which reattaches www-web-2 once the volume detaches from the old node.
Exercise
You delete web-0 with kubectl delete pod web-0. What happens to www-web-0, and what name does the replacement Pod have?
Show answer
The PVC www-web-0 is kept. The replacement Pod is named web-0 again and mounts the same claim.