π©Ί Understanding Liveness and Readiness Probes in Kubernetes β Complete Guide
In Kubernetes, your applications donβt just run. Theyβre continuously watched, checked, and healed by the system itself.
This self-monitoring capability is powered by Liveness and Readiness Probes β vital for keeping containers healthy and available.
Think of them like a nurse and a receptionist at a clinic:
- One checks if you’re alive (Liveness)
- The other decides if you’re ready to see patients (Readiness)
Letβs break it down from the ground up β with examples and real-world use cases.

π¦ What Are Probes in Kubernetes?
A probe is a Kubernetes mechanism to check the health or status of a container. Kubernetes uses these checks to decide whether to:
- Restart a container
- Wait before routing traffic
- Keep a pod in service
K8s uses three types of probes:
Probe Type | Purpose |
---|---|
Liveness | Checks if the container is still running and should be restarted |
Readiness | Checks if the app is ready to serve traffic |
Startup (Optional) | Checks if the app has finished starting (used with slow boot apps) |
𧬠Liveness Probe β “Is the container alive?”
Purpose:
If the liveness probe fails, Kubernetes will restart the container. This helps recover from crashes or deadlocks where the container looks fine (running), but is internally frozen.
Real-World Analogy:
A nurse walks into the room and checks if the patient has a pulse. If not β call emergency services (restart the pod).
Example (YAML):
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3
Configuration Explained:
httpGet
: Hits the/healthz
endpointinitialDelaySeconds
: Wait 10s before starting checksperiodSeconds
: Check every 5sfailureThreshold
: 3 consecutive failures trigger a restart
π’ Readiness Probe β “Is the container ready to receive traffic?”
Purpose:
If the readiness probe fails, Kubernetes removes the pod from the service endpoint list β without restarting it.
This helps during:
- App initialization
- Temporary downtime (e.g., DB not ready)
Real-World Analogy:
The receptionist checks if the doctor is ready to see patients. If not, they hold the queue β not call the ambulance.
Example (YAML):
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 3
π§ Probe Types
Type | How it works |
---|---|
httpGet | Sends HTTP GET to a path |
tcpSocket | Checks if TCP port is open |
exec | Runs a shell command (e.g., curl , ps aux ) |
Example – exec
:
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 10
π§ Advanced Use Cases & Best Practices
1. Separate Liveness and Readiness
Don’t use the same endpoint for both. Why?
- Liveness failure causes a restart
- Readiness failure just removes from load balancer
π Example:
/healthz
β deep checks (DB connection, cache)/ready
β shallow checks (service responsive?)
2. Avoid Premature Restarts
Use appropriate initial delay and failure thresholds, especially for:
- Slow boot apps
- Apps with warm-up routines
Bad config = too many restarts = crashing apps
3. Use Startup Probes for Monoliths
For apps that take a long time to start, use startupProbe to delay liveness checks until fully started.
startupProbe:
httpGet:
path: /start
port: 8080
failureThreshold: 30
periodSeconds: 10
4. Donβt Abuse Exec Probes
Running shell commands inside containers:
- Consumes CPU
- Can fail if shell tools are missing
- Use
httpGet
for web apps,tcpSocket
for basic checks
5. Testing Your Probes
Simulate failures with:
- Kill the health endpoint temporarily
- Monitor restarts via
kubectl describe pod
and logs - Use
kubectl get endpoints
to verify readiness
π Monitoring & Observability
Track probe failures via:
- kubectl describe pod
- Events in logging tools
- Prometheus metrics via exporters (e.g., kube-state-metrics)
π Final Summary: Choosing the Right Probe
Scenario | Use |
---|---|
App might hang or deadlock | Liveness Probe |
App takes time to initialize | Readiness + Startup Probe |
App temporarily loses DB connection | Readiness Probe only |
App returns 200 OK but has internal issues | Use deep readiness checks |
Stateless microservice | Liveness + Readiness (default combo) |
π Final Thoughts
Probes are one of the most powerful β yet often misunderstood β features in Kubernetes.
Used correctly, they:
- Save your pods from unnecessary restarts
- Protect your users from broken apps
- Boost uptime and resilience
In the world of Kubernetes, probes are the heartbeat of healthy apps.
Leave a Reply