FIELD NOTESKUBERNETES

Liveness, readiness and startup probes: which to use, and the one that causes outages

Readiness decides traffic, liveness decides restarts, startup decides when the other two begin. Why a liveness probe that checks the database restarts every replica at once, and safe defaults for all three.

By Zorp3 min readPublished
ON THIS PAGE
One Pod's probes: the startup probe holds back the other two until the app has started; readiness adds the Pod to the Service's endpoints or removes it, and liveness has the kubelet restart the container. Drawn in archhy.

Kubernetes has three probes and each answers a different question. Readiness decides whether a Pod gets traffic, liveness decides whether a container is restarted, and startup decides when the other two may begin. Put a readiness probe on everything that serves requests. Add a startup probe for anything slow to boot. Add a liveness probe only when a restart would actually cure what it detects, because a careless one turns a slow afternoon into an outage.

Three questions, three consequences#

A probe is only as dangerous as what happens when it fails, so start there.

  • Readiness fails: the Pod's address leaves the endpoints of every Service that selects it. Nothing restarts, and probing carries on, so the Pod comes back when it recovers. It runs for the container's whole life, not just at boot.
  • Liveness fails: the kubelet kills the container and the restart policy brings it back. Any state in memory is gone, and so is every request it was handling.
  • Startup fails: the same kill. Until it succeeds, neither of the other two runs at all.

Read that list as a cost scale. A wrong readiness probe costs some capacity for a while. A wrong liveness probe costs a restart, and it can restart every replica at once.

The liveness probe that causes outages#

The common mistake is a liveness probe pointed at a health endpoint that checks the database, the cache and a downstream API. The database has a bad minute; every replica fails its probe in the same window; the kubelet restarts all of them together. The database recovers to find a fleet of cold processes reconnecting at once, and your users are left with nothing at all.

The second way in is the defaults. A probe times out after one second and fails after three misses ten seconds apart. Under heavy load, a garbage-collection pause or a queue of requests can push a perfectly healthy process past one second three times in a row. The Pod is killed, its traffic moves to the others, and they are now busier than the one that just died. That is the cascade the Kubernetes documentation warns about, and it arrives exactly when you need the capacity most. A tight CPU limit makes it likelier, because a throttled container answers probes late too; requests and limits explains why.

So the test for a liveness probe is one question: would restarting this container fix the thing this check detects? A deadlocked worker, yes. A slow database, never. If your process crashes cleanly when it is broken, the restart policy already handles it and you may not need a liveness probe at all.

Safe defaults#

  • Readiness: on every container that receives traffic. Make it cheap. Have it fail while the process cannot serve: warming up, draining, overloaded. A readiness probe also means a new Pod gets no traffic until it passes, which is what makes a blue/green switch or a rolling update safe.
  • Dependencies belong in readiness only when another replica could answer without them. If every replica shares the same database, checking it empties the Service in one go, and clients typically get a refused connection, or a 503 from whatever proxy sits in front, instead of your own clear error.
  • Liveness: check the process alone, on a light endpoint, and give it a larger failure threshold than readiness. Then a struggling Pod is taken out of rotation long before anything kills it.
  • Startup: for slow starts, instead of a long initialDelaySeconds. Its budget is the failure threshold multiplied by the period. Once it passes, liveness keeps its normal sensitivity, rather than being blunted for the whole life of the container to cover the first two minutes.

For a service that can take up to five minutes to load its data:

YAML
startupProbe:
  httpGet: { path: /livez, port: 8080 }
  periodSeconds: 10
  failureThreshold: 30     # up to 300 seconds to start
livenessProbe:
  httpGet: { path: /livez, port: 8080 }
  timeoutSeconds: 3
  failureThreshold: 6      # a minute of failures before a restart
readinessProbe:
  httpGet: { path: /readyz, port: 8080 }
  failureThreshold: 2

Two endpoints, not one: /livez answers "is the process stuck?", /readyz answers "should I get traffic now?". Keeping them separate also lets an instance take itself out of service for maintenance without being restarted for it.

Probes are easy to describe and awkward to get right by reading. Gazeek's CKAD course has a guided lab, "Health checks with probes", in its observability and debugging module.

The diagram#

The picture follows one Pod through its life: the startup probe gating the other two, readiness adding and removing it from the Service, and liveness handing it to the kubelet for a restart. Open it in archhy and press Make a copy to adapt it.