How to use readiness and liveness probes?
· Category: Kubernetes
Short answer
Readiness probes determine if a container is ready to receive traffic. Liveness probes determine if a container is healthy and should be restarted. Startup probes handle slow-starting containers.
Steps
- Define the probe type: HTTP, TCP, or exec.
- Set
initialDelaySeconds,periodSeconds, andfailureThreshold. - Add the probe to the container spec.
Example
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
Tips
- Keep health check endpoints lightweight.
- Use readiness probes to prevent traffic to initializing Pods.
- Use startup probes for slow-starting containers to avoid premature liveness failures.
Common issues
- Overly aggressive probes can overwhelm the application.
- Missing readiness probes cause traffic to reach unready Pods.
- Liveness probes that are too sensitive cause unnecessary restarts.
- Probes on shared endpoints may report healthy for partial failures.