Liveness, Readiness & Startup Probes
A running process isn't necessarily a working process. It may be deadlocked, still loading a cache, or unable to reach its database. Probes let the kubelet ask the container how it's doing, and act on the answer:
| Probe | Question | On failure |
|---|---|---|
| readinessProbe | "Can you serve traffic right now?" | Pod is removed from Service endpoints (not restarted) |
| livenessProbe | "Are you still alive, or stuck?" | Container is restarted |
| startupProbe | "Have you finished starting?" | Liveness and readiness are held off until it succeeds; restarted if it never does |
containers:
- name: api
image: ghcr.io/acme/api:2.3.1
ports: [{name: http, containerPort: 8000}]
startupProbe:
httpGet: {path: /healthz, port: http}
periodSeconds: 5
failureThreshold: 24 # up to 2 minutes to start
readinessProbe:
httpGet: {path: /ready, port: http}
periodSeconds: 5
failureThreshold: 2
livenessProbe:
httpGet: {path: /healthz, port: http}
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3Probe mechanisms
| Type | Success when |
|---|---|
httpGet |
HTTP status 200–399 |
tcpSocket |
The port accepts a TCP connection |
exec |
The command exits with 0 |
grpc |
The gRPC health check returns SERVING |
Timing parameters
| Field | Default | Meaning |
|---|---|---|
initialDelaySeconds |
0 | Wait before the first probe |
periodSeconds |
10 | How often to probe |
timeoutSeconds |
1 | How long one probe may take |
failureThreshold |
3 | Consecutive failures before acting |
successThreshold |
1 | Consecutive successes to count as healthy again (must be 1 for liveness/startup) |
A probe only "fails" after failureThreshold consecutive failures. A single slow response doesn't trigger anything. The worst-case time until a stuck container is restarted is about initialDelaySeconds + periodSeconds × failureThreshold. This model feeds a sequence of probe results through those rules:
def evaluate(results, period, failure_threshold, success_threshold=1, kind="liveness"):
healthy, fails, oks = True, 0, 0
for i, ok in enumerate(results):
t = i * period
if ok:
fails, oks = 0, oks + 1
if not healthy and oks >= success_threshold:
healthy = True
print(f"t={t:3}s ok -> ready again")
continue
else:
oks, fails = 0, fails + 1
if healthy and fails >= failure_threshold:
healthy = False
action = "restart container" if kind == "liveness" else "remove from endpoints"
print(f"t={t:3}s FAIL -> {fails} consecutive failures: {action}")
if kind == "liveness":
fails = 0
healthy = True
continue
print(f"t={t:3}s {'ok ' if ok else 'FAIL'} (consecutive failures: {fails})")
print("liveness, period 10s, failureThreshold 3:")
evaluate([True, False, True, False, False, False, True], 10, 3)
print("readiness, period 5s, failureThreshold 2, successThreshold 2:")
evaluate([True, False, False, False, True, True, True], 5, 2, success_threshold=2, kind="readiness")liveness, period 10s, failureThreshold 3:
t= 0s ok (consecutive failures: 0)
t= 10s FAIL (consecutive failures: 1)
t= 20s ok (consecutive failures: 0)
t= 30s FAIL (consecutive failures: 1)
t= 40s FAIL (consecutive failures: 2)
t= 50s FAIL -> 3 consecutive failures: restart container
t= 60s ok (consecutive failures: 0)
readiness, period 5s, failureThreshold 2, successThreshold 2:
t= 0s ok (consecutive failures: 0)
t= 5s FAIL (consecutive failures: 1)
t= 10s FAIL -> 2 consecutive failures: remove from endpoints
t= 15s FAIL (consecutive failures: 3)
t= 20s ok (consecutive failures: 0)
t= 25s ok -> ready again
t= 30s ok (consecutive failures: 0)
The single failure at t=10s was forgiven; three in a row at t=30–50s caused a restart. For readiness, the Pod left the endpoints after two failures and needed two successes to return.
Startup probes protect slow starters
Without a startup probe, a liveness probe tuned for a running app (fail after 30 s) will kill an app that needs 90 s to start, over and over: a restart loop that never ends. The startup probe gives a generous budget once, then hands over to the liveness probe:
def simulate(start_time, liveness_budget, startup_budget=None):
budget = startup_budget if startup_budget is not None else liveness_budget
if start_time <= budget:
return f"started after {start_time}s, liveness takes over"
return f"killed at {budget}s before it finished starting (needs {start_time}s) -> restart loop"
app_start = 90
print("liveness only (3 x 10s): ", simulate(app_start, 30))
print("startup probe (24 x 5s = 120s):", simulate(app_start, 30, startup_budget=24 * 5))liveness only (3 x 10s): killed at 30s before it finished starting (needs 90s) -> restart loop
startup probe (24 x 5s = 120s): started after 90s, liveness takes over
What should each endpoint check?
- Liveness should check only the process itself ("is my event loop responding?"). Never check dependencies like the database: if the database goes down, restarting every API Pod won't fix it and only causes a restart storm.
- Readiness may check dependencies the Pod can't work without, and should fail during graceful shutdown so traffic drains first.
- Keep probe handlers cheap and fast; they run every few seconds on every Pod.
Warning: A missing readiness probe means "Ready as soon as the container starts". Rolling updates will then send traffic to Pods that aren't listening yet, causing errors on every release.
kubectl describe pod api-7d9f-x2k4p | grep -A3 -i liveness
kubectl get events --field-selector reason=UnhealthySample output:
Warning Unhealthy 12s (x3 over 32s) kubelet Liveness probe failed: HTTP probe failed with statuscode: 500
Normal Killing 12s kubelet Container api failed liveness probe, will be restartedTest yourself
A readiness probe fails repeatedly. What happens?
- The container is restarted
- The Pod is removed from Service endpoints until it passes again
- The node is drained
- The Deployment is deleted
Why shouldn't a liveness probe check the database connection?
- It is too slow
- A database outage would restart every Pod without fixing anything
- Databases don't support HTTP
- Liveness probes can't open connections
What is the startup probe for?
- Pulling the image
- Giving slow-starting apps time before liveness checks begin
- Running init scripts
- Choosing a node