All guides

Readiness, liveness and startup probes in Kubernetes

Three probes answer three different questions. Most probe trouble comes from asking one of them the wrong question.

A desk with two monitors showing code

What each probe asks

  • Startup: has the application finished starting? Until it passes, the other two probes wait. If it never passes, the container is restarted.
  • Readiness: can this pod take traffic right now? While it fails, the pod is taken out of the Service's endpoints. It is not restarted.
  • Liveness: is this process stuck beyond repair? When it fails, the kubelet restarts the container.

An example with all three

startupProbe:
  httpGet: { path: /healthz, port: 8080 }
  periodSeconds: 5
  failureThreshold: 30      # up to 150 seconds to start

readinessProbe:
  httpGet: { path: /ready, port: 8080 }
  periodSeconds: 5
  failureThreshold: 3

livenessProbe:
  httpGet: { path: /healthz, port: 8080 }
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3

Two endpoints, on purpose. /healthz answers from the process alone: if the web server can reply, it is alive. /ready checks what this pod needs before it can serve, such as an open connection pool or a warmed cache.

Four mistakes that cause outages

  1. A liveness probe that checks the database. When the database slows down, every pod fails liveness and restarts at once. A short database problem becomes a full outage. Liveness should depend on the process only.
  2. One endpoint for readiness and liveness. A pod that is busy but healthy gets restarted when it only needed a pause from traffic.
  3. No startup probe on a slow starter. The liveness probe fires before the application is up and the pod restarts in a loop. Give slow starters a startup probe with a generous failureThreshold.
  4. Timeouts left at the default. timeoutSeconds defaults to 1. Under load a healthy pod can take longer than that to answer, so set it from what you measure.

How to check yours

Run kubectl describe pod on a pod that restarted and read the events at the bottom. A line that says the liveness probe failed tells you which of the four you have.

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides