Sub topic 4
Readiness probes: when is a new Pod available?
This chapter assumes you can read and apply YAML manifests, use kubectl get and describe, and know how Pods, labels, and Services relate. It also assumes you know that a Deployment replaces Pods through ReplicaSets.
Running is not the same as ready
A rolling update replaces old Pods with new ones. The Deployment controller must decide when a new Pod can count as a replacement. If it counted a Pod as soon as its container started, a slow application could receive traffic before it could answer.
Kubernetes separates two ideas:
- Running: the container process has started.
- Ready: the Pod passes its readiness probe, so it should receive traffic.
A readiness probe is a check the kubelet runs against a container. While the check fails, the Pod's Ready condition is False. Services remove the Pod from their endpoints, and the Deployment does not count it as available.
Adding a readiness probe
The Deployment from the topic's example includes this probe:
readinessProbe:
httpGet:
path: /
port: 80
periodSeconds: 5The kubelet sends an HTTP GET to port 80 every 5 seconds. A status code from 200 to 399 counts as success. Anything else, or a timeout, counts as failure.
These fields tune the probe:
| Field | Meaning | Default |
|---|---|---|
| `initialDelaySeconds` | Wait before the first probe | 0 |
| `periodSeconds` | Time between probes | 10 |
| `timeoutSeconds` | Time allowed for each probe | 1 |
| `failureThreshold` | Consecutive failures before the Pod becomes not ready | 3 |
| `successThreshold` | Consecutive successes before the Pod becomes ready | 1 |
How readiness controls the rollout
The Deployment controller counts a Pod as available when it is ready. If you set minReadySeconds, the Pod must also stay ready for that many seconds. Chapter 10 covers that field.
Rolling update limits (maxSurge and maxUnavailable) are measured in available Pods. With maxUnavailable: 0, the controller removes an old Pod only after a new Pod is available.
Watching it happen
Apply the manifest, change the image, and watch the Pods:
kubectl apply -f web.yaml
kubectl set image deployment/web web=nginx:1.27
kubectl get pods -l app=web -wA new Pod shows Running with 0/1 in the READY column until the probe succeeds. Then it shows 1/1. Only then does an old Pod begin terminating.
Common errors
- No readiness probe. Kubernetes treats the Pod as ready once its containers start. Traffic can arrive before the application can serve it.
- A probe that never succeeds. A wrong path or port keeps new Pods at
0/1. The old Pods stay in service, so users see no outage, but the rollout stalls. Runkubectl describe podand look forReadiness probe failedevents. - A probe that checks too much. If the probe calls a shared database and that database is slow, every Pod can become not ready at once. Probe what the Pod itself needs.
- Confusing readiness with liveness. A failed liveness probe restarts the container. A failed readiness probe only removes the Pod from traffic.
Exercise
A Deployment has replicas: 4, maxSurge: 1, maxUnavailable: 0, and no readiness probe. The new image starts its container but needs 30 seconds before it can serve requests. What goes wrong during the rollout, and what fixes it?
Show answer
Kubernetes treats each new Pod as ready as soon as its container starts. The controller then removes old Pods while the new ones cannot yet answer, so requests fail for about 30 seconds per step. Add a readinessProbe that succeeds only when the application can serve requests. The controller then waits for each new Pod to become ready before it removes an old one.
Exercise
During an update, kubectl get pods shows a new Pod at 0/1 Running for several minutes, and the old Pods are still serving. Which command do you run to find the cause, and what do you look for?
Show answer
Run kubectl describe pod <pod-name> and read the Events section for "Readiness probe failed" messages. They show the HTTP status or connection error, which usually points to a wrong path, wrong port, or an application that fails to start properly.