Containers and orchestration
Health probes
Startup, readiness and liveness probes decide when a container gets traffic and when it gets restarted. Liveness should be shallow, because a deep check can turn one dependency blip into a full restart storm.
Probes are how the kubelet asks a container whether it is alive and ready for traffic. There are three, and each one does a different thing when it fails. Mixing them up is one of the most common ways to turn a small outage into a large one.
The big idea
Think of a shop. Startup is the period when the staff are still unpacking the stock, so nobody is judged yet. Readiness is whether the shop is open to customers. If it fails, the shop stops taking visitors but stays open. Liveness is whether the building is still standing. If it fails, you rebuild the shop. You rebuild only when it is truly wedged.
| Probe | Failure means | Typical use |
|---|---|---|
| Startup | Keep trying, and hold off the other probes | Slow JVMs or migrations at boot |
| Readiness | Remove the pod from Service endpoints | A dependency is down, a cache is warming, or the pod is draining |
| Liveness | Restart the container | A deadlock or a stuck event loop, not "the database is slow" |
Walking through it
startupProbe:
httpGet: { path: /livez, port: 8080 }
failureThreshold: 30
periodSeconds: 5 # up to 150 s to start
readinessProbe:
httpGet: { path: /readyz, port: 8080 }
periodSeconds: 5
livenessProbe:
httpGet: { path: /livez, port: 8080 }
periodSeconds: 10
failureThreshold: 3The startup probe allows up to 30 tries at 5 seconds each, which is 150 seconds of boot time. Until it passes, liveness does not run, so a slow boot is not mistaken for a hang.
Now the deep-dependency trap. Imagine twelve replicas that all check the database in their liveness probe. The database times out for 20 seconds. Every liveness check fails. Kubernetes restarts all twelve together. Each one reopens its connection pool, against a database that is still recovering. The outage lasts longer than the database blip did.
Put the same check on readiness instead, and the result is correct. The pods are removed from the endpoints for 20 seconds, the load balancer returns 503 during that window, and the pods return when the database recovers. That is fail closed, without a restart storm.
Two more rules:
- Set timeouts with headroom. A
timeoutSeconds: 1on a busy endpoint fails under normal load. - Avoid heavy probes. A
/healthendpoint that runs queries adds load of its own. PreferhttpGetor the native gRPC health protocol overexecprobes, which fork a process every period.
Readiness also gates rollouts. A Deployment does not remove old pods until new ones are ready. A readiness probe that never passes stalls the rollout forever. kubectl rollout status shows where it is stuck.
Common mistakes
- Deep checks on liveness. A dependency blip becomes a restart storm.
- No startup probe on a slow boot. Liveness kills the container during initialization.
- Aggressive timeouts. Fast probes fail under real load and cause false restarts.
Check yourself
- The database is slow for 20 seconds. The database check is on readiness. What happens to traffic? The pods leave the endpoints for that window, and the load balancer returns 503. They come back when the database recovers. No pods restart.
- Why does a slow-booting JVM need a startup probe? Without it, liveness starts checking during boot and restarts the container before it finishes initializing.
Key takeaways
- Readiness decides traffic. Liveness decides restarts. Never mix them.
- Keep liveness shallow, so it only fires for a wedged process.
- Use a startup probe for slow boots, and give probes timeouts with headroom.
Further learning
The rollout side of readiness is in rollouts and graceful termination. The process signals that end a container are in graceful shutdown.
Configure Liveness, Readiness and Startup ProbesThis page shows how to configure liveness, readiness and startup probes for containers. For more information about probes, see Liveness, Readiness and Startup Probes. Before you beginYou need to have a Kubernetes clus…Kubernetes
Related
Kubernetes in production
Requests and limits, probes, autoscaling, disruption budgets, packaging and the mistakes that cause outages.
Resource requests, limits and QoS
Requests decide where a pod fits. Limits decide what happens when it uses too much. CPU over its limit is throttled, while memory over its limit is killed.
Rollouts and graceful termination
How a rolling update swaps pods safely, and the order of events when a pod is deleted. Traffic has to stop before the process does, and requests longer than the grace period get cut off.