Kubernetes Readiness Probe and Liveness Probe
Configure Kubernetes readiness probes and liveness probes for pod health checks. HTTP, TCP, exec, and gRPC probe examples with best practices.
π‘ Quick Answer: Use readinessProbe to control when a pod receives traffic (fails = removed from Service). Use livenessProbe to restart unhealthy containers (fails = container restart). Use startupProbe for slow-starting apps. Always set
initialDelaySecondsto give your app time to start, and donβt make livenessProbe depend on external services.
The Problem
Kubernetes needs to know if your application is healthy and ready to receive traffic. Without proper health checks, Kubernetes might send traffic to broken pods or fail to restart crashed applications.
The Solution
Configure three types of probes:
- Liveness Probe - Is the container alive? (Restart if not)
- Readiness Probe - Is the container ready for traffic? (Remove from service if not)
- Startup Probe - Has the container started? (Protect slow-starting containers)
Understanding the Difference
| Probe | Purpose | Failure Action |
|---|---|---|
| Liveness | Detect deadlocks/hangs | Restart container |
| Readiness | Detect temporary unavailability | Remove from Service endpoints |
| Startup | Wait for slow startup | Prevent liveness checks during startup |
Basic HTTP Probe Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0
ports:
- containerPort: 8080
# Liveness: Restart if this fails
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
# Readiness: Remove from service if this fails
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3Probe Types
HTTP Probe (Most Common)
livenessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Authorization
value: Bearer tokenTCP Probe (For non-HTTP services)
livenessProbe:
tcpSocket:
port: 3306Command Probe (For custom checks)
livenessProbe:
exec:
command:
- cat
- /tmp/healthygRPC Probe (Kubernetes 1.24+)
livenessProbe:
grpc:
port: 50051
service: my.health.ServiceProbe Parameters Explained
| Parameter | Default | Description |
|---|---|---|
initialDelaySeconds | 0 | Wait before first probe |
periodSeconds | 10 | How often to probe |
timeoutSeconds | 1 | Probe timeout |
successThreshold | 1 | Consecutive successes to be healthy |
failureThreshold | 3 | Consecutive failures to be unhealthy |
Startup Probe for Slow Applications
For applications that take a long time to start (Java apps, ML models):
startupProbe:
httpGet:
path: /healthz
port: 8080
# Allow up to 5 minutes for startup (30 * 10 seconds)
failureThreshold: 30
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
port: 8080
# Once startup succeeds, use tighter liveness checks
periodSeconds: 10
failureThreshold: 3Best Practices
β DO
# Separate endpoints for liveness and readiness
livenessProbe:
httpGet:
path: /healthz # Only checks if app is alive
readinessProbe:
httpGet:
path: /ready # Checks dependencies (DB, cache, etc.)β DONβT
# Don't check external dependencies in liveness probe!
livenessProbe:
httpGet:
path: /ready # This checks DB connection
# If DB is slow, ALL pods restart = cascading failure!Recommended Health Check Implementations
Liveness endpoint (/healthz):
- Return 200 if the process is running
- Donβt check external dependencies
- Fast response (< 100ms)
Readiness endpoint (/ready):
- Check database connections
- Check cache availability
- Check required external services
- Return 503 if not ready
Complete Example: Node.js Application
// healthz - for liveness (simple)
app.get('/healthz', (req, res) => {
res.status(200).json({ status: 'alive' });
});
// ready - for readiness (checks dependencies)
app.get('/ready', async (req, res) => {
try {
// Check database
await db.ping();
// Check Redis
await redis.ping();
res.status(200).json({ status: 'ready' });
} catch (error) {
res.status(503).json({
status: 'not ready',
error: error.message
});
}
});Common Mistakes
1. Liveness checks external dependencies
# BAD: If DB is slow, all pods restart
livenessProbe:
httpGet:
path: /api/users # Queries database2. Timeout too short
# BAD: Probe times out during GC pauses
livenessProbe:
httpGet:
path: /healthz
timeoutSeconds: 1 # Too short for Java apps3. No startup probe for slow apps
# BAD: App takes 60s to start, but liveness starts at 10s
livenessProbe:
initialDelaySeconds: 10 # App not ready yet = restart loop4. ReadinessProbe too aggressive
# BAD: Single failure removes from service
readinessProbe:
failureThreshold: 1 # Flaky during deploymentsDebugging Probes
Check probe status:
kubectl describe pod my-app-xxx
# Look for "Liveness" and "Readiness" in ConditionsCheck events for probe failures:
kubectl get events --field-selector reason=UnhealthyTest the endpoint manually:
kubectl exec -it my-app-xxx -- curl localhost:8080/healthzSummary
Youβve learned how to:
- Configure liveness, readiness, and startup probes
- Choose the right probe type for your use case
- Implement health check endpoints correctly
- Avoid common pitfalls that cause cascading failures
Key takeaway: Keep liveness probes simple, use readiness probes for dependency checks.
References
π Go Further with Kubernetes Recipes
Love this recipe? Thereβs so much more! This is just one of 100+ hands-on recipes in our comprehensive Kubernetes Recipes book.
Inside the book, youβll master:
- β Production-ready deployment strategies
- β Advanced networking and security patterns
- β Observability, monitoring, and troubleshooting
- β Real-world best practices from industry experts
βThe practical, recipe-based approach made complex Kubernetes concepts finally click for me.β
π Get Your Copy Now β Start building production-grade Kubernetes skills today!
Frequently Asked Questions
What is a readiness probe in Kubernetes?
A readiness probe tells Kubernetes when a pod is ready to accept traffic. If the readiness probe fails, the pod is removed from Service endpoints (no traffic routed to it) but NOT restarted. Use readiness probes for applications that need warm-up time, dependency checks, or graceful degradation.
Whatβs the difference between liveness and readiness probes?
Liveness probes detect if a container is deadlocked or hung β a failing liveness probe causes Kubernetes to restart the container. Readiness probes detect if a container can handle requests β a failing readiness probe removes the pod from load balancing but doesnβt restart it. Use both together for robust health checking.
How do I configure a readiness probe?
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 3This checks /healthz every 10 seconds. After 3 consecutive failures, the pod is marked unready and removed from Service endpoints.
Frequently Asked Questions
What is a readiness probe in Kubernetes?
A readiness probe tells Kubernetes whether a pod is ready to receive traffic. If the readiness probe fails, the pod is removed from Service endpoints β no traffic is routed to it. Unlike liveness probes, a failed readiness probe does NOT restart the pod.
What is the difference between liveness and readiness probes?
Liveness probe: Is the container alive? On failure β restart the container. Use to detect deadlocks and hangs. Readiness probe: Is the container ready for traffic? On failure β remove from Service endpoints. Use for slow startup and dependency checks.
Should I use liveness probes?
Be careful with liveness probes. Never check external dependencies (database, cache) in liveness probes β if the DB is down, restarting your app wonβt fix it and creates a thundering herd. Set initialDelaySeconds high enough and use failureThreshold: 3 minimum.
What is a startup probe?
Startup probes (Kubernetes 1.20+) run only during container startup. Once the startup probe succeeds, liveness and readiness probes take over. Use startup probes for slow-starting applications (Java, ML models).
What probe types are available?
HTTP GET (success = 200-399), TCP socket (success = port open), exec command (success = exit code 0), and gRPC health check (Kubernetes 1.27+).
See also: CrashLoopBackOff Troubleshooting, HPA Guide

Recommended
Kubernetes Recipes β The Complete Book100+ production-ready patterns with detailed explanations, best practices, and copy-paste YAML. Everything in one place.
Get the Book βLearn by Doing
CopyPasteLearn β Hands-on Cloud & DevOps CoursesMaster Kubernetes, Ansible, Terraform, and MLOps with interactive, copy-paste-run lessons. Start free.
Browse Courses βπ Deepen Your Skills β Hands-on Courses
Courses by CopyPasteLearn.com β Learn IT by Doing
