Skip to main content
Running workloadsLesson 5 of 14

When a Pod Dies (Self-Healing)

When the desired state and the actual state drift apart, Kubernetes brings them back in line on its own. Let's see who revives what, and how, when one container dies and when a whole node stops.

node-1 statusReady
app-a restarts0
Ready / desired2 / 2
Control planenode-1node-2API serverRecords stateControllersWatch nodes·RSSchedulerPicks a nodekubeletnode-1app-aPodkubeletnode-2app-bPodapp-cReplacementheartbeatheartbeat
RequestResponse / reportWatchAppears in a later step

What you will learn

  • A dead container is restarted by the kubelet on the same node
  • CrashLoopBackOff means "waiting to retry"
  • When a node stops, controllers recreate pods on another node
  • Each kind of self-healing takes a different amount of time

Self-healing by failure level​

What stoppedWho revives itResultTime taken
ContainerThat node's kubeletContainer restarts inside the same podSeconds (up to 5 min apart if repeated)
NodeControllers + schedulerNew pod created on another nodeMinutes (includes the default 5 min wait)
Pod deleted manuallyReplicaSet controllerNew pod createdSeconds

Try it yourself​

kubectl get pods -o wide # RESTARTS and node per Pod
kubectl logs <pod> --previous # Logs from the last run
kubectl describe pod <pod> # Last State and Back-off events
kubectl get nodes # NotReady nodes
kubectl get pod <pod> -o jsonpath='{.spec.tolerations}' # not-ready wait (300s by default)

Check yourself

  1. A container exits from an unhandled error, but its node is fine. Who brings it back, and how fast?
  2. A pod shows CrashLoopBackOff. Where should you look for the cause?
  3. A node loses power. Why does it take minutes, not seconds, before its pods run elsewhere?

Further reading: Pod Lifecycle · Configure Liveness, Readiness and Startup Probes