Skip to main content

Rollouts and rollback

Stage 1 · Liftoff

You will be able to: predict how a booking rollout proceeds with two replicas, explain why a bad release stalls without an outage, say which changes start a rollout and which do not, and list what rollout undo cannot restore.

Deployments introduced the mechanism: one ReplicaSet per template version, replicas shifted across, gated on readiness. This chapter applies it to Apollo's services, where releases touch databases, configuration and other services, and where "roll back" has limits you need to plan for.

The pace with two replicas​

Apollo's services run replicas: 2 with the default strategy. The defaults round differently:

  • maxSurge: 25% of 2 = 0.5, rounded up to 1: one extra Pod may exist.
  • maxUnavailable: 25% of 2 = 0.5, rounded down to 0: no Pod may be missing.

So a booking rollout starts one new Pod and removes no old Pod until that new one is Ready. Two ready Pods serve throughout.

Why a bad release stalls instead of breaking​

If the new Pod cannot pull its image, crashes on start, or keeps failing its readiness probe, it never becomes Ready, so the old Pods are never removed. Passengers keep being served by the old version. The rollout reports Progressing=False once its deadline passes.

The safety net is only as good as the readiness check. If booking's /readyz returns 200 while it cannot reach its database, a broken release becomes Ready, old Pods are retired, and the outage arrives on schedule. Stage 4's probes chapter covers what readiness should test.

Knobs that shape a rollout​

Field or commandDefaultWhat it changes
maxSurge / maxUnavailable25% / 25%How many Pods may be added or missing at once (above)
minReadySeconds0How long a new Pod must stay Ready before it counts as available. Catches versions that pass readiness, then crash a few seconds later
progressDeadlineSeconds600How long without progress before the Deployment reports Progressing=False (reason ProgressDeadlineExceeded). It reports; it does not roll back
revisionHistoryLimit10How many old ReplicaSets are kept, and so how far back rollout undo can go
kubectl rollout pause / resumeStop acting on template changes, make several edits, then roll them out as one revision
kubectl rollout status --timeoutWaits for the rollout and exits non-zero if it fails or times out: the check a script or CI job should use

Nothing in Kubernetes rolls back by itself. A stalled rollout stays stalled until a person or a tool runs undo or ships a fix. The planned Stage 10 Argo Rollouts mission adds automated analysis and rollback.

What starts a rollout, and what does not​

A rollout starts only when the Pod template changes. That catches people out with configuration:

ChangeNew ReplicaSet and rollout?
Image tagYes
A literal env value in the templateYes
Probes, resources, labels in the templateYes
replicasNo: the current ReplicaSet is just resized
Editing a ConfigMap or Secret the Pods readNo. Pods keep the values they started with (env vars), or see the file change only if the app re-reads it
kubectl rollout restartYes: it adds a timestamp annotation to the template

To roll out a configuration change, either run kubectl rollout restart, or make the template depend on the config (for example, an annotation holding a hash of the ConfigMap, which tools like Helm and Kustomize can generate).

What rollback restores​

kubectl rollout undo copies the previous ReplicaSet's template back into the Deployment, and the same rolling process runs towards it. It restores the Pod template and nothing else.

Plan releases so that going back is safe.

Expand, deploy, contract​

When a release changes the database schema, split it so both the old and new code can run against the database at every moment:

  1. Expand: add the new columns or tables without removing anything. Old and new code both work.
  2. Deploy the new version. A rollback is safe, because the old code still works on the expanded schema.
  3. Contract: once the new version has proven itself, remove the old columns in a later release.

During a rolling update, old and new Pods serve at the same time anyway, so this discipline is needed even when nothing goes wrong.

Diagnose a rollout​

kubectl rollout status deploy/booking -n apollo-airlines --timeout=30s
kubectl get rs,pods -n apollo-airlines -l app=booking
kubectl describe pod -n apollo-airlines -l app=booking | grep -E 'Failed|BackOff|Readiness'
kubectl rollout history deploy/booking -n apollo-airlines
kubectl rollout undo deploy/booking -n apollo-airlines
Stuck withLikely cause
ImagePullBackOffWrong tag or registry: the kubelet cannot pull
Running, 0/1 ReadyReadiness failing: bad config or a dependency it cannot reach
PendingScheduling or quota: no room for the surge Pod

Try it​

Unverified

Not yet run on a live cluster for this documentation revision. Uses a throwaway namespace on any cluster.

See which changes start a rollout, and what undo leaves behind:

kubectl create namespace roll-demo
kubectl -n roll-demo create configmap app-config --from-literal=COLOR=blue
kubectl -n roll-demo create deployment web --image=nginx:1.27-alpine --replicas=2
kubectl -n roll-demo set env deploy/web --from=configmap/app-config
kubectl -n roll-demo rollout status deploy/web
kubectl -n roll-demo rollout history deploy/web # 2 revisions: create, then set env

# Scaling does not create a revision
kubectl -n roll-demo scale deploy/web --replicas=3
kubectl -n roll-demo get rs # still one ReplicaSet with Pods

# Editing the ConfigMap does not start a rollout, and Pods keep the old value
kubectl -n roll-demo patch configmap app-config -p '{"data":{"COLOR":"green"}}'
kubectl -n roll-demo exec deploy/web -- printenv COLOR # blue
kubectl -n roll-demo rollout restart deploy/web # adds a restartedAt annotation
kubectl -n roll-demo rollout status deploy/web
kubectl -n roll-demo exec deploy/web -- printenv COLOR # green

# Undo restores the template, not the ConfigMap
kubectl -n roll-demo rollout undo deploy/web
kubectl -n roll-demo rollout status deploy/web
kubectl -n roll-demo exec deploy/web -- printenv COLOR # still green
kubectl delete namespace roll-demo
  • scale resized the current ReplicaSet; only template changes made new revisions.
  • The ConfigMap edit reached running Pods only after a restart, and undo could not take it back.

Common misconceptions​

  • "A stalled rollout means an outage." The old Pods usually keep serving.
  • "Rollback undoes the release." It restores the template, not its side effects.
  • "Editing a ConfigMap rolls out the change." It does not touch the template, so no rollout starts.
  • "Rollback fixes a bad ConfigMap." The ConfigMap is outside the template; undo leaves it as it is.

Check yourself​

Why did users keep getting 200s during a stalled booking rollout?

The new Pod never became Ready, so the old Pods were never removed.

You change LOG_LEVEL in booking's ConfigMap. Why does nothing happen, and how do you apply it?

The Pod template did not change, so the Deployment does nothing, and running processes keep the value they read at start. Run kubectl rollout restart deploy/booking, or tie the template to the ConfigMap's content.

Does rolling back undo a booking written by the buggy version?

No. Rollback restores the Pod template only; data and external effects stay.

Where this leads​

Rollback cannot restore data that lived in a Pod that no longer exists. The last Liftoff chapter, Ephemeral state, names exactly what a replacement Pod loses.

References​