Learn Labs
Running Applications

Probes

Startup, readiness, and liveness, measured

A process being up doesn't mean it can serve. The kubelet asks each container three different questions, with three different consequences.

startupProbe:"have you finished starting?" (the others wait for it)httpGet: { path: /healthz, port: http }periodSeconds: 2failureThreshold: 30up to 60 s to startreadinessProbe:"should you get traffic right now?"httpGet: { path: /readyz, port: http }periodSeconds: 2failureThreshold: 2fail -> removed from Service endpoints, NOT restartedlivenessProbe:"are you broken beyond repair?"httpGet: { path: /healthz, port: http }periodSeconds: 5failureThreshold: 3fail -> container killed and restarted

The app has a 5-second warm-up (STARTUP_SECONDS) during which /readyz returns 503, and endpoints to make it unready or "sick" on demand.

Measured

./scripts/lab.sh probes.py
endpoints: ['web-5865ccc48d-2g5q7', 'web-5865ccc48d-mfktj', 'web-5865ccc48d-x2gp6']

web-5865ccc48d-2g5q7 says not ready -> removed from endpoints after 2.2s
5 s of traffic: {'web-5865ccc48d-mfktj': 48, 'web-5865ccc48d-x2gp6': 41}  (web-5865ccc48d-2g5q7 got 0)
pod still running, restarts: 0
ready again -> back in endpoints after 0.9s

web-5865ccc48d-2g5q7 says not alive -> container restarted after 16.4s (restarts: 2)
 ready again 5.7s after the liveness failure (startup 5 s warm-up included)
traffic during it: 392 requests, 392 ok, errors: none
 event: Unhealthy  x6  Liveness probe failed: HTTP probe failed with statuscode: 500
 event: Killing    x2  Container web failed liveness probe, will be restarted
16–20 sreadiness2 sno traffic, no restartliveness3 × 5 s + preStopkillreadyseconds →
  • Readiness removed the pod from the endpoints in 2.2 s (2 failures × 2 s). It received zero of the next 89 requests, and it was not restarted: once it reported ready again, it was back in under a second.
  • Liveness restarted the container after 16 to 20 s across runs: 3 failures × 5 s, plus the 5-second preStop sleep that also runs before a liveness kill. With startup and readiness gating, no client saw an error.

Designing the endpoints

  • Readiness can reflect the pod's own ability to serve (warming up, shutting down, overloaded). Be careful with shared dependencies there too: if every pod goes unready when Redis is down, the Service has no endpoints and clients get errors from the proxy instead of a degraded response from the app. This app's /api/visits returns 503 on its own when Redis is down, and stays ready.
  • Startup probes exist for slow starters (JVMs, large caches). Without one, a liveness probe with a short timeout kills the container before it finishes starting, forever: a crash loop that looks like a bug in the app.

Lab

  1. Run probes.py. Then change the liveness probe to /readyz and make a pod unready. What happens now, and why is that worse?
  2. Set STARTUP_SECONDS: "30" and roll the Deployment. How long does the rollout take now, and which probe decides when each new pod gets traffic?
  3. Stop Redis (kubectl -n shop scale sts redis --replicas=0) and request /api/whoami and /api/visits. Which still work?

On this page