CKAD — Liveness Probes
Liveness Probe — Keep Apps Running
A liveness probe detects when an application is stuck. When the probe fails, Kubernetes restarts the container. This is your safety net against deadlocks, infinite loops, and unresponsive processes.
HTTP Liveness Probe
The most common pattern — check a health endpoint:
apiVersion: v1
kind: Pod
metadata:
name: web-liveness
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 3
Kubernetes sends a GET request to http://localhost:80/ every 10 seconds. If it gets 3 consecutive non-2xx/3xx responses, the container is restarted.
Exec Liveness Probe
Use a command to check health — useful for non-HTTP applications:
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec
spec:
containers:
- name: app
image: busybox:1.36
command: ["/bin/sh", "-c"]
args:
- |
touch /tmp/healthy
sleep 30
rm /tmp/healthy
sleep 600
livenessProbe:
exec:
command: ["cat", "/tmp/healthy"]
initialDelaySeconds: 5
periodSeconds: 5
kubectl apply -f liveness-exec.yaml
# Watch the Pod — it will restart after ~35 seconds
kubectl get pod liveness-exec -w
# After 30s, /tmp/healthy is deleted → probe fails → container restarts
What happens step by step:
- Container starts and creates
/tmp/healthy - Liveness probe runs
cat /tmp/healthy— succeeds (exit code 0) - After 30 seconds, the file is deleted
- Probe runs
cat /tmp/healthy— fails (exit code 1) - After
failureThresholdconsecutive failures, Kubernetes restarts the container
Next: Readiness Probes