Sub topic 11
Probes during rolling updates
This chapter assumes you know how Deployments, ReplicaSets, and Services relate, and that you have read the earlier chapters on readiness and liveness probes. It covers how a Deployment uses readiness to decide whether a rollout can continue.
How a rolling update uses readiness
A Deployment with the default RollingUpdate strategy replaces Pods gradually. It creates a new ReplicaSet and scales it up while it scales the old one down. The Deployment controller does not look at your application. It looks at Pod status, and a Pod counts as available only when it is Ready. That status comes from the readiness probe.
Two settings control the pace:
| Field | Meaning | Default |
|---|---|---|
| `maxSurge` | How many Pods above `replicas` may exist during the update | 25% (rounded up) |
| `maxUnavailable` | How many Pods below `replicas` may be unavailable | 25% (rounded down) |
| `minReadySeconds` | How long a Pod must stay Ready before it counts as available | 0 |
| `progressDeadlineSeconds` | How long the Deployment may make no progress before it is marked failed | 600 |
With replicas: 4 and the defaults, the controller may run 5 Pods and must keep at least 3 available. It starts one new Pod and waits until that Pod is Ready. Only then does it remove an old Pod.
A Deployment tuned for safe rollouts
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 4
minReadySeconds: 10
progressDeadlineSeconds: 300
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: registry.example.com/web:1.1.0
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /ready
port: 8080
periodSeconds: 5
failureThreshold: 3Setting maxUnavailable: 0 means an old Pod is removed only after a new Pod is available. Capacity never drops below replicas, but the cluster needs room for one extra Pod. minReadySeconds: 10 makes a new Pod stay Ready for 10 seconds before it counts. This catches a Pod that passes its probe once and then fails.
What happens when the new version is broken
Suppose version 1.1.0 starts but /ready always returns 503. The new Pod never becomes Ready, so the controller never counts it as available. It does not remove more old Pods. The old Pods keep serving traffic, and the Service never sends requests to the broken Pod. The rollout stalls.
After progressDeadlineSeconds, the Deployment gets the condition Progressing=False with reason ProgressDeadlineExceeded. Kubernetes does not roll back on its own. You must run kubectl rollout undo deploy/web or fix the image.
kubectl rollout status deploy/web
kubectl get rs -l app=web
kubectl rollout undo deploy/webWhy a missing readiness probe is dangerous
Without a readiness probe, a Pod is Ready as soon as its containers start. The controller then considers the new Pod available straight away and keeps replacing old Pods. If the application needs 30 seconds to warm up, or is broken, the Service sends it traffic anyway. You can end up with every old Pod gone and only unready or broken Pods left.
Liveness and startup probes during updates
A slow-starting new version with only a liveness probe may be killed before it finishes starting. The restarts push the Pod into CrashLoopBackOff, and the rollout stalls. A startup probe holds off liveness and readiness checks until the application has started. This keeps a slow but healthy version from stalling the update.
Exercise
A Deployment has replicas: 3, maxSurge: 1, and maxUnavailable: 0. The new image never passes its readiness probe. How many old Pods are still serving after 10 minutes, and what do you need to do?
Show answer
All 3 old Pods are still serving. The controller created one new Pod and cannot remove an old one until the new Pod is available. After progressDeadlineSeconds (600 seconds by default) the Deployment reports ProgressDeadlineExceeded. You must run kubectl rollout undo deploy/web or deploy a fixed image, because Kubernetes does not roll back automatically.