Startup, Liveness and Readiness Probes

A slow app can be killed mid boot, while another stays up but loses traffic. How does the Kubelet tell a slow start from a hang with startup, liveness and readiness probes, and what does each failure change?

Play the animation 6 steps, animated, plays on a computer or a tablet

Startup, Liveness and Readiness Probes diagram: Container probes

Startup, Liveness and Readiness Probes, step by step

  1. Kubelet runs startupProbe against the container every periodSeconds, with an httpGet, tcpSocket, grpc or exec handler. While it runs, livenessProbe and readinessProbe are held shut and never execute, so a slow boot never reads as a liveness failure. If it exhausts failureThreshold, Kubelet kills the container and restartPolicy decides what follows.

    Play from step 1
  2. The startupProbe succeeds once. Kubelet retires it for the lifetime of this container instance and never runs it again, and the two probes it was holding are released. From here livenessProbe and readinessProbe run independently, each on its own periodSeconds, and neither waits for the other.

    Play from step 2
  3. The readinessProbe passes successThreshold times in a row and may run ahead of its period until the container is Ready. Kubelet flips the Pod Ready condition to True and the Pod endpoint in the EndpointSlice flips to ready=true, so new connections start reaching the Pod. All spec.readinessGates conditions must be True first.

    Play from step 3
  4. The readinessProbe alone fails failureThreshold consecutive times. The Pod endpoint in the EndpointSlice is marked ready=false rather than removed, so new connections stop reaching it. Nothing is restarted and restartCount stays 0, because a readiness failure only moves traffic away.

    Play from step 4
  5. The livenessProbe fails failureThreshold consecutive times on its own period. Kubelet kills the container and starts a fresh instance per restartPolicy, so restartCount becomes 1 and the endpoint stays ready=false. The Pod object is not replaced and keeps its IP, because a probe restarts a container and never a Pod.

    Play from step 5
  6. The replacement container starts from the beginning. Kubelet runs startupProbe again and holds the other two probes shut until it passes. Then readinessProbe succeeds, and the endpoint flips back to ready=true. The restartCount carries over and climbs with every restart, which is how a restart loop is told apart from a healthy run.

    Play from step 6

Sources