Sub topic 10
Readiness probes: telling Kubernetes when a Pod can take traffic
This chapter assumes you can read Pod and Deployment YAML, use kubectl get and kubectl describe, and know that a Service sends traffic to Pods that match its selector.
Running is not the same as ready
A container can be running and still be unable to serve requests. It may be loading configuration, warming a cache or waiting for a database. Kubernetes cannot see this on its own. It only knows that the process started.
A readiness probe is a check that the kubelet runs against a container to decide whether the Pod is ready to receive traffic. The result sets the Pod's Ready condition:
- While the probe fails, the Pod stays
Runningbut shows0/1in the READY column. Services remove it from their endpoints. - When the probe passes, the Pod becomes
Readyand starts receiving traffic. - A failing readiness probe does not restart the container. That is the job of a liveness probe, which is a separate check.
Without a readiness probe, a Pod counts as ready as soon as its containers start.
The probe in the Deployment
The Deployment from the earlier chapter includes this probe:
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 5The kubelet waits 3 seconds after the container starts, then sends GET / on port 80 every 5 seconds. Any HTTP status from 200 to 399 counts as success.
| Field | Meaning | Default |
|---|---|---|
| `initialDelaySeconds` | Wait before the first check | 0 |
| `periodSeconds` | Time between checks | 10 |
| `timeoutSeconds` | How long one check may take | 1 |
| `failureThreshold` | Consecutive failures before the Pod is marked not ready | 3 |
| `successThreshold` | Consecutive successes before it is marked ready | 1 |
Besides httpGet, a probe can use tcpSocket, which checks that a port accepts connections, or exec, which runs a command inside the container and succeeds on exit code 0.
Why this matters for rollouts
During a rolling update, the Deployment controller counts a new Pod as available only after it is ready. With maxUnavailable: 0, the controller will not scale the old ReplicaSet down until a new Pod passes its probe. The probe therefore gates the whole rollout.
If the new image is broken and the probe never passes, the new Pods never become ready. The old Pods keep serving, and the rollout stalls instead of taking the application down. A later chapter covers diagnosing that stall.
Common errors
- No probe at all. The rollout moves on as soon as containers start, so traffic can reach Pods that are not ready.
- A probe that is too strict. If it checks a dependency such as a database, a brief outage there marks every Pod not ready at once, and the Service has no endpoints.
- A delay or timeout that is too short. A slow-starting application fails its checks before it can answer, so it never becomes ready.
- Wrong port or path. The probe fails forever, and the rollout never completes.
You can see probe failures in the Pod events:
kubectl get pods -l app=web
kubectl describe pod -l app=webLook for Readiness probe failed in the Events section.
Exercise
A Deployment uses maxUnavailable: 0 and a new image whose readiness probe always fails. What happens to the old Pods, and why?
Show answer
The old Pods keep running and serving traffic. The new Pods never become ready, so the controller never counts them as available. With maxUnavailable set to 0, it will not scale the old ReplicaSet down, and the rollout stalls instead of causing an outage.
Exercise
Does a failing readiness probe restart the container?
Show answer
No. It only marks the Pod not ready and removes it from Service endpoints. Restarting on failure is the job of a liveness probe.