Kubernetes Field Guide · Chapter 10 of 16
Health checks: liveness, readiness and startup probes
A running process is not the same as a working app. Probes tell Kubernetes when to send traffic, when to restart and when to wait. Get them right and deploys are invisible to users; get them wrong and probes cause the outage.
- 30 min
- Advanced
- Hands-on
- Free
By Joshua Sequeira, founding engineer running Kubernetes in production. Updated .
By the end you can
0 of 4
Live lab in this chapter
A real-feeling terminal and a live cluster map, right in your browser. Every command block below has a ▶ Run in lab button.
Running is not ready
Without probes, Kubernetes knows one thing: the process exists. It sends traffic the moment a container starts, even while the app is still loading, and it never restarts an app that is stuck but still running. Three probes fix that:
| Probe | Question | On failure |
|---|---|---|
| Startup | Has it finished starting? | Keep waiting; the other probes are paused. Restart only if it never passes. |
| Readiness | Can it serve traffic right now? | Remove from Service endpoints. No restart. |
| Liveness | Is it broken beyond recovery? | Restart the container. |
Each probe can be an HTTP GET (any 2xx or 3xx passes), a TCP connect, a command run in the container, or a gRPC health check. By default they run every 10 seconds, time out after 1 second and act after 3 failures in a row.
Turn probes on and off and put the app in different states:
Interactive
Same app, different probes
Gets traffic?
Kubelet action
Liveness
Liveness is for one situation: the process is alive but will not recover by itself, such as a deadlock. Keep it cheap and local: an endpoint that only proves the process can respond. Be generous with timeouts, because a liveness probe that fails under load restarts pods at the worst possible moment.
Readiness
Readiness controls traffic, and it is what makes rolling updates safe: a new pod only counts as available, and an old pod is only removed, once the new one is ready. A pod can also become unready later, for example while warming a cache or when overloaded, and come back without a restart.
Step through it
A pod fails readiness, and traffic quietly moves away
- Kubeletruns probes
- ContainerGET /ready
- API serverpod status
- EndpointSliceready pod IPs
- kube-proxyrouting rules
Step 0 of 5
Press Play, or step through with Next.
Startup
Use a startup probe for slow starters, such as JVM apps or apps that load large models or caches. It allows failureThreshold × periodSeconds to start (30 × 5s = 150s below) and only then hands over to liveness. Before startup probes existed, people used a long initialDelaySeconds on liveness, which delays failure detection forever after.
containers:
- name: api
image: ghcr.io/example/api:2.3.0
ports:
- containerPort: 8080
startupProbe:
httpGet: { path: /healthz, port: 8080 }
periodSeconds: 5
failureThreshold: 30
livenessProbe:
httpGet: { path: /healthz, port: 8080 }
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
readinessProbe:
httpGet: { path: /ready, port: 8080 }
periodSeconds: 5
failureThreshold: 2
lifecycle:
preStop:
sleep: { seconds: 10 }
terminationGracePeriodSeconds: 40- Up to 150s to start. Liveness and readiness wait for it.
- Process-level only. timeoutSeconds 3 avoids restarts from slow replies.
- Can it serve? Checked often so traffic shifts quickly.
- Keep serving for 10s while endpoints and load balancers stop sending traffic.
- Total time for preStop plus graceful shutdown before SIGKILL. The default is 30.
Probe mistakes that cause outages
The most common one first: a liveness probe that is less patient than the app. Tune the numbers and watch what the kubelet does over three minutes.
Interactive · Probe tuner
A slow-starting app meets your liveness probe
The rest of the list:
- Checking dependencies in liveness. The database blips, every pod fails liveness, every pod restarts together. The outage you had becomes a bigger one.
- Tight timeouts on liveness. Under load, replies slow down, probes time out, pods restart, the remaining pods get more load. A cascading failure caused by the safety net.
- No readiness probe. Every deploy sends traffic to pods that are not listening yet. Users see errors on each release.
- Using the same endpoint for both. Then readiness cannot shed load without also triggering restarts.
- Ignoring shutdown. When a pod is deleted, it is removed from endpoints at the same time SIGTERM is sent, and load balancers take a few seconds to notice. An app that exits instantly drops those in-flight requests. Handle SIGTERM by finishing current requests, and add a short
preStopsleep.
Hands-on: zero-downtime deploys
The lab is docked at the bottom of your screen.
Live lab · no install
Zero-downtime with probes
Break one pod and watch it leave the Service without a single failed request.
- Tasks0/6
Add a readiness probe
web-probes.yaml checks GET / every few seconds before sending traffic.
kubectl apply -f web-probes.yaml kubectl rollout status deployment/webBreak readiness on one pod
Delete the page nginx serves. The probe starts failing.
POD=$(kubectl get pods -l app=web -o name | head -n 1) kubectl exec $POD -- rm /usr/share/nginx/html/index.htmlAlive but not ready: 0/1 Running. It stays up, but gets no traffic.
Confirm it left the Service
kubectl get pods -l app=web kubectl get endpointslices -l kubernetes.io/service-name=webHeal it by hand
Put the page back. Readiness passes and the pod rejoins.
kubectl exec $POD -- sh -c "echo ok > /usr/share/nginx/html/index.html"Add a liveness probe so it heals itself
Edit web-probes.yaml in the Files tab: add a livenessProbe next to readinessProbe (httpGet path / on port 80, failureThreshold 3). Apply it.
edit web-probes.yamlBreak it again and watch the restart
After three failed checks the kubelet restarts the container, which comes back from the image with the page restored.
POD=$(kubectl get pods -l app=web -o name | head -n 1) kubectl exec $POD -- rm /usr/share/nginx/html/index.html kubectl get pods -l app=webRESTARTS went to 1 and the pod is ready again, with nobody paged.
- Lab complete. Keep experimenting, or press Reset to start again.
- ready
- starting / not ready
- failing
- terminating
Prefer your own machine? The same steps on a local cluster
Replace web with a version that has a readiness probe. Save as web-probes.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.27
readinessProbe:
httpGet:
path: /
port: 80
periodSeconds: 3
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
memory: 128Mikubectl delete hpa web --ignore-not-found
kubectl apply -f web-probes.yaml
kubectl rollout status deployment/web
Break readiness on one pod by deleting the page nginx serves, and watch it leave the Service without restarting:
POD=$(kubectl get pods -l app=web -o name | head -n 1)
kubectl exec $POD -- rm /usr/share/nginx/html/index.html
kubectl get pods -l app=web
kubectl get endpointslices -l kubernetes.io/service-name=web
NAME READY STATUS RESTARTS AGE
web-7c5d9b8f6d-2kqvx 0/1 Running 0 2m
web-7c5d9b8f6d-h8m4n 1/1 Running 0 2m
web-7c5d9b8f6d-t6w9p 1/1 Running 0 2m
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
web-8qfzl IPv4 80 10.244.0.31,10.244.0.32 40m0/1 Running- Alive but not ready: no restart, no traffic.
2 endpoints- The broken pod has left the Service. Users never reach it.
Mini mission
Make liveness fix it
The broken pod above stays broken forever. Add a liveness probe so Kubernetes repairs it by itself, without breaking healthy pods during slow moments.
Reveal one safe solution
Add this under the container, next to readinessProbe, then apply and repeat the rm:
livenessProbe:
httpGet:
path: /
port: 80
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3After about 30 seconds the kubelet restarts the container, which starts from the image again with index.html back, so readiness passes and RESTARTS shows 1. Here liveness and readiness share a path only because nginx has nothing else to check; in your own apps, keep them separate.
Check yourself
Quiz
0 of 4 answered