Kubernetes Probes: Liveness, Readiness, Startup
How livenessProbe, readinessProbe, and startupProbe differ, what each failure triggers, and how failing readiness removes a Pod from EndpointSlices.
TL;DR
Readiness controls traffic (failure removes the Pod from EndpointSlices without restarting it), liveness controls restarts (failure kills a deadlocked container), and startup protects slow boots by delaying liveness and readiness until the first success.
Intent
Separate traffic-gating (readinessProbe) from process-restarting (livenessProbe) and slow-boot protection (startupProbe) so you don't trigger restart loops or cascading outages.
Problem
Without probes, Kubernetes assumes a Pod is ready the millisecond its container process starts—sending user traffic to an app that is still warming caches or loading config. Conversely, putting a heavy database check inside livenessProbe causes kubelet to restart every Pod in the fleet whenever the database has a 5-second hiccup.
Solution
| Probe | Failure action | Use it for |
|---|---|---|
readinessProbe | Sets Ready=False; removes Pod IP from EndpointSlice | Temporary inability to serve traffic (warming up, draining, overloaded) |
livenessProbe | Kills and restarts the container | Unrecoverable deadlocks where only a restart fixes the process |
startupProbe | Delays liveness & readiness; kills container if failureThreshold expires | Legacy/heavy apps that take 30–120s to boot |
Real-world analogy
▶ Flow: watch it work
Failing Readiness Probe → Removed from EndpointSlice → No Traffic
Press Start or tap any step dot to trace the path.
▸All steps (4)
Code
Minimal Deployment probe configuration for an HTTP service (such as labs/docker-multistage-next serving /healthz):
# Partial Pod container spec (not run against a cluster)
containers:
- name: web
image: ghcr.io/example/web:1.0.0
ports:
- containerPort: 3000
startupProbe:
httpGet:
path: /healthz
port: 3000
failureThreshold: 12
periodSeconds: 5
readinessProbe:
httpGet:
path: /readyz
port: 3000
periodSeconds: 5
failureThreshold: 2
livenessProbe:
httpGet:
path: /healthz
port: 3000
periodSeconds: 15
failureThreshold: 3When you DON'T need this
- Non-Kubernetes platforms: Static sites on Cloudflare Workers/Pages, Docker Compose (
HEALTHCHECK), or serverless functions don't use Kubernetes probes orEndpointSlices. - Kubernetes
Job/CronJobbatch Pods: Batch jobs run to completion and exit; they don't serve Service traffic and shouldn't havereadinessProbeorlivenessProbe. - Cost / complexity trade-off: Probes cost almost nothing in CPU (a lightweight
/healthzhandler returning200 OKtakes microseconds), but poorly tuned timeouts (timeoutSeconds: 1on a GC-pausing app) or DB-coupled liveness probes can cause self-inflicted outages. Keep/healthzcheap and local to the process.
When to use / when to avoid
- Every long-running Kubernetes Deployment behind a Service should define a readinessProbe.
- Add startupProbe if cold start can exceed liveness initialDelaySeconds.
- Checking external databases or third-party APIs inside livenessProbe (causes cascading restarts).
- Setting identical aggressive thresholds for liveness and readiness.
How to implement
Expose cheap local health endpoints
Have /healthz verify the process event loop is alive (no external DB calls) and /readyz verify local initialization is complete.
Configure readinessProbe first
Set periodSeconds and failureThreshold so rolling updates only shift traffic once new Pods are ready.
Add startupProbe for slow starters
Use startupProbe instead of a huge initialDelaySeconds on livenessProbe so fast boots become ready immediately while slow boots aren't killed.
Pros / Cons
- Zero-downtime rolling updates: new Pods receive traffic only after passing readiness.
- Self-healing for wedged processes via livenessProbe.
- Badly designed liveness probes (calling external DBs) turn brief downstream blips into CrashLoopBackOff storms.
- Too-tight timeoutSeconds can fail under normal GC or CPU spikes.
Relations
Check yourself
Check Yourself
1. A Pod's readinessProbe fails 3 times, while its livenessProbe continues to pass. What happens?
2. Why is querying Postgres inside a livenessProbe usually an anti-pattern?
Sources
Related Notes
Pods, ReplicaSets, and Deployments
How Kubernetes layers Pods, ReplicaSets, and Deployments to run stateless workloads and perform zero-downtime rollouts and rollbacks.
Requests, Limits, QoS & OOMKilled
How Kubernetes CPU/memory requests and limits shape QoS classes, CPU throttling vs OOMKilled (exit 137), plus a fictional training postmortem example.