Core Kubernetes · 09
Rollouts and Probes
1.What starts a rollout ?
A rollout swaps Pods from an old ReplicaSet to a new one. Pods are never edited in place.
- Trigger : any change under
.spec.template(image, env, labels...). Each one makes a new ReplicaSet, a new revision. - Changing
replicasis scaling, not a rollout. .: RollingUpdate (default) or Recreate.spec. strategy. type - Recreate : all old Pods gone first, then the new ones. Downtime by design.
ReplicaSets and scaling : Deployments and Scaling.
2.Step size
- maxSurgePods allowed above replicas. 25%, rounds up.
- maxUnavailablePods allowed to be unavailable. 25%, rounds down.
- both 0Rejected : the rollout could never move.
A number or a percent. It is not one Pod at a time : 10 replicas start 3 extra Pods and drop 2 at once.
Terminating Pods do not count as available, so the real count can briefly pass max Pods until their grace period ends.
| replicas | surge | unavailable | min available | max Pods |
|---|---|---|---|---|
| 1 | 1 | 0 | 1 | 2 |
| 3 | 1 | 0 | 3 | 4 |
| 4 | 1 | 1 | 3 | 5 |
| 10 | 3 | 2 | 8 | 13 |
Not a strategy typeBlue/green flips one Service selector from the old Deployment to the new one. Canary runs both behind one shared label, or splits traffic by weight (Gateway API, Knative, Flagger from the Flux project).
3.Readiness sets the pace
A new Pod is available once it is Ready and stays Ready for minReadySeconds (default 0). Beyond maxUnavailable, old Pods only go as new ones become available.
- No readinessProbe ? Ready the moment it starts, so traffic and the rollout run ahead of the app.
- A new Pod that never gets Ready stalls the rollout. Old Pods keep serving.
- Capacity can dip by default.
maxUnavailable: 0keeps full capacity.
| Progressing | reason | rollout status |
|---|---|---|
| True | NewReplicaSetAvailable | exits 0 |
| True | ReplicaSetUpdated | keeps waiting |
| False | ProgressDeadlineExceeded | exits 1 |
Stalled is only a statusNo progress for
progressDeadlineSeconds (default 600, must be greater than minReadySeconds) gives the False row. The controller keeps retrying and never rolls back. That is your job.4.Revisions and rollback
- Each ReplicaSet is a revision.
revisionHistoryLimit(default 10) is how many old ones stay. 0 means no undo. rollout undoreverts the Pod template only.- The reused ReplicaSet gets a new number : rev 2 comes back as rev 4.
- Resume a paused Deployment before you undo.
In short : A template change makes a new ReplicaSet, maxSurge and maxUnavailable size each step, readiness sets the pace, and a stalled rollout waits for you to undo it.
1.Three probes, three jobs
The kubelet runs the probes. Liveness and readiness run side by side and never wait for each other.
| Probe | On failure | Use it for |
|---|---|---|
| startup | Kill, restartPolicy | Slow starters. The others wait. |
| liveness | Restart, same Pod, same node | Hangs. Never a dependency check. |
| readiness | No Service traffic, no restart | Warm-up, overload, deps down |
One check per probe. No probe counts as Success.
- execthe command exits 0
- httpGetstatus 200 to 399
- tcpSocketthe port accepts a connection
- grpchealth check says SERVING (GA v1.27)
2.Probes in a Pod template
containers:
- name: nginx
image: nginx:1.16.1
ports: [{name: http, containerPort: 80}]
startupProbe:
httpGet: {path: /, port: http}
periodSeconds: 5
failureThreshold: 12 # up to 60s to start
readinessProbe:
httpGet: {path: /, port: http}
periodSeconds: 5
livenessProbe:
tcpSocket: {port: http}
3.Timing
| Field | Default | Note |
|---|---|---|
| initialDelaySeconds | 0 | From container start. Liveness and readiness also wait for startupProbe |
| periodSeconds | 10 | How often |
| timeoutSeconds | 1 | One try fails after this |
| successThreshold | 1 | Only 1 for liveness, startup |
| failureThreshold | 3 | Fails in a row = failed |
Startup budgetfailureThreshold x periodSeconds. Here 12 x 5 = 60s. The docs example uses 30 x 10 = 300s.
4.Readiness gates
spec.adds a Pod condition that an outside controller sets.readinessGates[]. conditionType - Ready = containers ready and every gate True. Missing counts as False.
PodDisruptionBudgetpolicy/v1. Limits voluntary evictions (Eviction API,
kubectl drain). Deleting Pods and rolling updates skip it, since maxUnavailable is the rollout's own budget. Healthy = Ready, and maxUnavailable: 0 means drain never ends.5.Commands
| Command | What it does |
|---|---|
| kubectl set image deployment/web nginx=nginx:1.16.1 | Changes the template image, so a rollout starts |
| kubectl rollout status deployment/web --timeout=5m | Waits. Exit 0 when done, 1 once past the deadline |
| kubectl annotate deployment/web kubernetes.io/change-cause="to 1.16.1" | Fills CHANGE-CAUSE in history (replaces --record) |
| kubectl rollout history deployment/web --revision=2 | Lists revisions, or one revision's template |
| kubectl rollout undo deployment/web --to-revision=2 | Back one revision, or to N. --dry-run=server previews |
| kubectl rollout pause / resume deployment/web | Batches edits into one revision (Deployments only) |
| kubectl rollout restart deployment/web | New Pods for all, through a normal rolling update |
| kubectl describe pod <pod> | Probe failures show as Warning Unhealthy events |
| kubectl create pdb web-pdb --selector=app=web --min-available=50% | A budget (or --max-unavailable, never both) |
In short : Startup holds the other probes off, liveness restarts a stuck container, readiness pulls a Pod out of traffic, and that same Ready flag paces rollouts and PDBs.