🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes: Liveness, Readiness and Startup Probes

A probe is a small health check that Kubernetes runs against a container. Liveness, readiness and startup probes each answer a different question about the container.

A liveness probe

A liveness probe asks the app itself if it is alive. The path only checks the app, never a database. A failed probe restarts the container.

livenessProbe:
  httpGet:
    path: /healthz
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 10

A readiness probe

A readiness probe asks if the app can take traffic. A pod that fails it stays running but leaves the Service. No traffic reaches it until it is ready.

readinessProbe:
  httpGet:
    path: /ready
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 5

A startup probe for slow starts

A slow app would fail its liveness probe before it finished starting. A startup probe gives it up to five minutes here. The other probes wait until it passes.

startupProbe:
  httpGet:
    path: /healthz
    port: 80
  failureThreshold: 30
  periodSeconds: 10

Example

kubectl apply -f web-probes.yaml
kubectl get pods -l app=web

Key points

  • Liveness probe: checks whether the container is still alive, and restarts it when it fails
  • Readiness probe: checks whether the container can take traffic, and keeps it out of the Service until it can
  • Startup probe: gives a slow app time to start before the other probes begin
  • Use a readiness probe to hold traffic back while an app warms up
  • Use a startup probe when an app needs a long time to start

In this example, the first command creates a Deployment with all three probes from the file. The second command reads the pods back. Both pods are ready, which proves the probes passed and the app is serving traffic.

Note

a liveness probe must never check a dependency, or a database outage becomes a cluster-wide restart festival

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Why must a liveness probe never check a dependency?