Skip to content

Deployments and rollouts

Draft: not yet run against a live cluster. Treat output as representative and check it on yours.

A rollout is a controlled race between new pods becoming Ready and old pods being removed. Readiness is the referee. Without a good readiness probe, Kubernetes will happily replace every working pod with a broken one and report success.

  1. A template change creates a new ReplicaSet. The Deployment controller hashes the pod template; a new hash means a new ReplicaSet, labelled with pod-template-hash.

  2. The controller scales new up and old down in steps, keeping within maxSurge and maxUnavailable. It only scales the old ReplicaSet down when new pods become available (Ready for minReadySeconds).

  3. Progress is tracked as a condition. The Progressing condition is updated as pods become available. If nothing improves for progressDeadlineSeconds, it becomes False with reason ProgressDeadlineExceeded. Kubernetes does not roll back automatically; it just stops and reports.

  4. Old ReplicaSets are kept at zero replicas, up to revisionHistoryLimit, so kubectl rollout undo can scale one back up.

Terminal window
kubectl create deployment web --image=nginx:1.27 --replicas=3
kubectl rollout status deployment/web
kubectl set image deployment/web nginx=nginx:1.27-alpine
kubectl rollout status deployment/web --timeout=120s
kubectl rollout history deployment/web
kubectl get rs -l app=web
kubectl set image deployment/web nginx=nginx:does-not-exist
kubectl rollout status deployment/web --timeout=60s # times out
kubectl rollout undo deployment/web

During the broken rollout, all three old pods keep serving. With three replicas, 25% maxUnavailable rounds down to 0 and 25% maxSurge rounds up to 1, so Kubernetes adds one new pod and removes nothing until that pod is available, which it never is.

A rollout hits ProgressDeadlineExceeded. Does Kubernetes roll back automatically?

No. It marks the Deployment as failed to progress and stops. You roll back with kubectl rollout undo or by reverting the change.

Which change starts a rollout: replicas: 5, or a new environment variable in the container?

The environment variable, because it changes the pod template. Scaling replicas doesn’t create a new ReplicaSet.

Why can't you change a Deployment's selector?

The selector defines which pods the Deployment owns. Kubernetes makes it immutable so ownership can’t silently change.

Maps to: CKA: Workloads and Scheduling; CKAD: Application Deployment. Check the current exam curriculum, since domain names change between revisions.