Q&A-6Define readiness and liveness for a backend.
Answer
The 90-second answer. Readiness answers "should this instance get traffic right now?" Liveness answers "is this process wedged in a state a restart can fix?" The consequence is what separates them. A failed readiness check removes the pod from the Service's endpoints: the process keeps running, in-flight requests finish, no restart. A failed liveness check makes kubelet kill the container and restart it under the pod's restartPolicy. So readiness is a traffic decision, liveness is a recovery decision, and the test for putting anything in a liveness check is: would restarting this process plausibly fix it? If the answer is no, it does not belong there.
Mechanism. kubelet runs each probe every periodSeconds (default 10) with timeoutSeconds (default 1) and acts after failureThreshold consecutive failures (default 3). Readiness failure flips the pod's Ready condition to false; the endpoint controller drops the pod IP from the Endpoints/EndpointSlice and kube-proxy stops routing new connections to it. Liveness failure makes kubelet kill the container; the restart backoff doubles from 10s to a 5-minute cap and resets after the container has run 10 minutes. A startup probe suppresses both others until it passes, which is how you protect a slow boot from being killed.
# Kubernetes 1.29, Go HTTP server on :8080
startupProbe:
httpGet: { path: /livez, port: 8080 }
periodSeconds: 5
failureThreshold: 60 # up to 5 min to boot
readinessProbe:
httpGet: { path: /readyz, port: 8080 }
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 2 # unready after ~10s
livenessProbe:
httpGet: { path: /livez, port: 8080 }
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3 # restart after ~30s wedged| probe | who acts | action | process survives? |
|---|---|---|---|
| readiness | endpoint controller, via kubelet status | pod removed from Endpoints | yes |
| liveness | kubelet | container killed, restarted per policy | no |
| startup | kubelet | gates the other two until it passes | yes |
Trade-offs. The design decision interviewers push on is whether either check touches a shared dependency. Coupling readiness to the database is defensible: if the instance genuinely cannot serve, shedding traffic is correct. But it converts a partial outage into a total one: every pod goes unready and the Service has zero endpoints. Coupling liveness to a shared dependency is almost never right, because the dependency being down is not something restarting your process fixes. The deciding criterion is whether the instance can still do useful work: a service that can answer from cache should stay ready when the primary is down.
Failure modes.
- Restart storm. Liveness probes a shared dependency; it blips; all replicas fail together, restart in lockstep, and hammer the recovering dependency with cold caches and fresh connection pools. Detect with
kube_pod_container_status_restarts_total: alert when a pod exceeds ~3 restarts in 10 minutes. - Flapping readiness. An intermittent probe failure churns the pod in and out of endpoints, resetting connections at the load balancer. Detect via endpoint add/remove events and 5xx rate during removal windows.
- Liveness too tight. With the config above, ~30s of unresponsiveness triggers a kill. A 45s stop-the-world GC pause or a saturated connection pool does exactly that, so you restart healthy pods. Detect by correlating restarts with GC pause and pool-wait metrics.
- Readiness that always passes. Traffic lands on pods that cannot serve, and you get 5xx with a green readiness signal. Detect by comparing 5xx rate against readiness success rate.
- Deadlock. Only liveness catches it; readiness alone leaves the pod in endpoints forever.
Keep readiness cheap and local: deep dependency checks belong in a separate endpoint or a synthetic monitor, not in the path that gates every request.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.