The kubelet runs probes against each container on a schedule and acts on the result.
text
┌─ startupProbe ─── fails ──▶ restart (until it passes, others wait)
container ─┼─ livenessProbe ── fails ──▶ restart the container
└─ readinessProbe ─ fails ──▶ Pod not Ready, removed from endpointsMechanisms
| Kind | Passes when |
|---|---|
httpGet | HTTP status 200-399 at path on port |
tcpSocket | something accepts a connection on port |
exec | the command exits 0 inside the container |
Timing
yaml
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5 # first probe after start
periodSeconds: 10 # then every 10 s
failureThreshold: 3 # consecutive failures before acting
timeoutSeconds: 1text
start ──5s──▶ probe ──10s──▶ probe ──10s──▶ probe
fail fail fail ──▶ 3 failures: actWhat to probe
Liveness: a path that only fails when the process is stuck. Readiness: a path that fails while the app cannot serve (warming caches, waiting on a dependency). Pointing liveness at a dependency makes the app restart every time the dependency blinks.
Reading the result
sh
kubectl describe pod <pod>text
Liveness: http-get http://:80/healthz delay=0s timeout=1s period=10s #success=1 #failure=3
Readiness: http-get http://:80/ delay=2s timeout=1s period=10s #success=1 #failure=3
Events:
Warning Unhealthy Liveness probe failed: HTTP probe failed with statuscode: 404
Normal Killing Container web failed liveness probe, will be restartedA rising RESTARTS column with Unhealthy events is a liveness problem. 0/1 READY with the container Running is a readiness problem.