Probes: Health Checks
Liveness Probe
Checks: "Is the app dead?"
Result: Restart Pod
Readiness Probe
Checks: "Can it handle traffic?"
Result: Remove from LoadBalancer
User Traffic
✅Healthy
Kubernetes needs to know the state of your application to manage it effectively. It does this through Probes.
By default, Kubernetes only checks if the container's process is running. If your app is deadlocked (but the process is running) or returning 500 errors, Kubernetes thinks it's fine. Probes solve this.
1. Liveness Probe
- Question: "Is the container still alive?"
- Action: If this fails, Kubernetes restarts the container.
- Use Case: Deadlocks, crashed application loops, memory leaks making the app unresponsive.
- Warning: Do not fail Liveness probes on external dependencies (like a database is down). If the DB is down, restarting the Pod won't fix it.
2. Readiness Probe
- Question: "Is the container ready to accept traffic?"
- Action: If this fails, Kubernetes stops sending traffic (removes IP from Service Endpoints). It does NOT restart the pod.
- Use Case: App is starting up, loading large cache, waiting for database connection, or is temporarily overloaded.
3. Startup Probe
- Question: "Has the container started yet?"
- Action: Disables other probes until this passes. If it fails after
failureThreshold, the pod is restarted. - Use Case: Legacy apps that take minutes to boot. Without this, the Liveness probe might kill the app before it finishes starting.
Example Configuration
apiVersion: v1
kind: Pod
metadata:
name: goproxy
spec:
containers:
- name: goproxy
image: k8s.gcr.io/goproxy:0.1
ports:
- containerPort: 8080
# Check if app is alive
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
# Check if app is ready for traffic
readinessProbe:
httpGet:
path: /readiness
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
💬 Feedback & Comments
Have a question or found a bug? Leave a comment below using your GitHub account.