Skip to main content
Running workloadsLesson 3 of 14

Zero-Downtime Deploys (Rolling Update)

Three pods running nginx 1.26 move to 1.27. During the change, user requests are never interrupted. Let's see how.

v1 pods3
v2 pods0
Pods serving3
v1 pods · nginx:1.26v2 pods · nginx:1.27UserChanges imageDeploymentDesired stateRS v1nginx:1.263RS v2nginx:1.27v1-anginx:1.26v1-bnginx:1.26v1-cnginx:1.26v2-anginx:1.27v2-bnginx:1.27v2-cnginx:1.27ServiceRoutes to Ready podsUser trafficMust not drop
RequestAppears in a later step

What you will learn

  • How Deployment, ReplicaSet, and pods relate
  • Why old pods shrink only after new pods are Ready
  • How maxSurge and maxUnavailable set the pace
  • Why rollback (rollout undo) is fast

Rolling update settings at a glance​

SettingMeaningIf increased
maxSurgeHow many pods may briefly exist above the desired countFinishes faster, but needs more spare resources
maxUnavailableHow many pods may briefly be missing below the desired countFinishes faster, but capacity drops for a while
readinessProbeChecks whether a new pod may receive requestsWithout it, pods get requests as soon as they start, which can cause errors

Try it yourself​

kubectl create deployment try-web --image=nginx:1.26 --replicas=3 # Throwaway Deployment
kubectl set image deployment/try-web nginx=nginx:1.27 # Change the image
kubectl rollout status deployment/try-web # Watch until done
kubectl get rs -l app=try-web # Old ReplicaSet stays at 0
kubectl rollout undo deployment/try-web # Roll back to 1.26
kubectl delete deployment try-web # Clean up

Check yourself

  1. During a rolling update of 3 pods with the default settings, when is an old v1 pod removed?
  2. The new v2 pods never pass their readiness probe. What happens to the rollout?
  3. Why can kubectl rollout undo roll back right away?

Further reading: Deployments · Performing a Rolling Update