Appearance

Rolling updates and rollback

Follow old and new replicas through a rolling update, then use revision history to recover from a failed release.

What you will understand

  • Predict which Pods a rolling update can add or remove at each step.
  • Recognize the evidence that tells you a release is stuck waiting for readiness.
  • Recover a Deployment by restoring a known Pod template revision.

Builds on: Deployments and ReplicaSets

How a rolling update replaces Pods

A catalog service has three healthy copies. You want to release a new container image while those copies keep answering requests. A rolling update changes the Pod template and switches traffic gradually as replacement Pods become ready. The Deployment keeps the old and new copies in separate ReplicaSets. You can watch their counts change as the rollout proceeds.

With maxSurge: 1 and maxUnavailable: 0, the Deployment can ask for a fourth replica while the three old ones are still available. It waits until the first new Pod becomes available before it scales down an old copy. The spare slot can then hold the next new Pod. The rule works as long as the cluster has room to schedule the extra copy and the updated application passes its checks.

Open Inspect the rollout to see when the first replacement becomes Ready, when the Deployment counts it as available, and which ReplicaSet scales down.

Replace the web Pods one at a time

With maxSurge 1 and maxUnavailable 0, an available new Pod makes room to retire an old copy.

  1. Deployment controllerCreate the new revision’s ReplicaSet
    New ReplicaSetThree old replicas continue serving.
  2. New ReplicaSetUse the one-Pod surge
    First new PodThe first new replica starts while the old copies remain available.
  3. First new PodBecome available
    Deployment controllerThe controller can remove an old copy and reuse the extra slot.
  4. Both ReplicaSetsRepeat the replacement
    New revisionThe updated Pods take over as the old ReplicaSet scales down.
Follow the sequence

With maxSurge 1 and maxUnavailable 0, an available new Pod makes room to retire an old copy.

Desired replicas are three, maxSurge is one, maxUnavailable is zero. Old replicas stay healthy; unrelated failures and terminating overlap are omitted from counts. The update policy cannot prevent independent application or node failures.

Inspect the rollout

Follow rollout-demo from nginx 1.27.5 to 1.28.0. Three replicas are desired, with maxSurge: 1, maxUnavailable: 0, and minReadySeconds: 5.

1 / 6

From kubectlTo API server

Update the Pod template

kubectl sets the image on the Deployment. The changed template starts a rollout. The existing Pods still use the old image.

Deployment template image
Before
nginx:1.27.5
After
nginx:1.28.0
Update the Pod template

kubectl sets the image on the Deployment. The changed template starts a rollout. The existing Pods still use the old image.

The trace shows one healthy rollout. Playback time is illustrative. ReplicaSet writes go through the API server. Other failures and overlap with terminating Pods are outside these counts.

The first new Pod is Ready for only two seconds. Can the Deployment retire an old replica yet?
Reveal prediction answer

It must wait for the new Pod to be Ready for all five seconds. At the two-second mark, the three old Pods still supply the full availability budget.

In the two-replica exercise, change a Pod template annotation. Compare rollout status and revision history, then undo and verify that the previous template is active.

Verify a rollout and undo in the Deployment lab
Explore another case

Choose how much capacity to keep available

Save the example as rollout-demo.yaml. The readiness probe asks nginx for /. Once a new Pod is ready, minReadySeconds: 5 makes it stay ready for at least five seconds before the Deployment counts it as available. progressDeadlineSeconds gives the controller a threshold for reporting a lack of progress. If that threshold expires, inspect the conditions before choosing a recovery.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: rollout-demo
spec:
  replicas: 3
  minReadySeconds: 5 # Stay ready before counting as available.
  progressDeadlineSeconds: 120 # Report a stalled rollout; not auto-rollback.
  revisionHistoryLimit: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: rollout-demo
  template:
    metadata:
      labels:
        app: rollout-demo
    spec:
      containers:
        - name: web
          image: nginx:1.27.5
          readinessProbe:
            httpGet:
              path: /
              port: 80
            periodSeconds: 5

Apply the original version and wait for it to complete. Record its revision from the history. Update the image and watch the two ReplicaSets. Their desired and ready counts can differ while Pods are starting. Stop the watch when you have seen the update finish or have enough evidence to investigate a stall.

kubectl apply -f rollout-demo.yaml
kubectl rollout status deployment/rollout-demo --timeout=180s
kubectl rollout history deployment/rollout-demo
# Inspect a controlled image update in your disposable lab.
kubectl set image deployment/rollout-demo web=nginx:1.28.0
kubectl get rs -l app=rollout-demo -w

Recover a release that gets stuck

In a disposable lab, try changing the image to a tag that does not exist. The new Pod can remain in ImagePullBackOff while the three old Pods stay up. Check the Deployment conditions and the new Pod’s events. Pick the known-good revision you recorded and use rollout undo to restore its Pod template. The controller reconciles toward that template and you can wait again for rollout status. Watch the same sequence in the recovery scene.

kubectl describe deployment rollout-demo
kubectl get pods -l app=rollout-demo
kubectl rollout history deployment/rollout-demo
# Choose the actual known-good revision from your own history.
kubectl rollout undo deployment/rollout-demo --to-revision=ACTUAL_GOOD_REVISION
kubectl rollout status deployment/rollout-demo --timeout=180s

What does Deployment rollback restore?

Undo restores a previous Pod template. Check the Deployment’s history, choose the intended revision, and verify the replacement Pods become available.

  1. Find the stalled revision

    Revision two references a bad image. New Pods fail while old available replicas remain under the configured budget.

  2. Select a retained template

    The progress deadline reports failure; it does not perform automatic rollback. An operator chooses an actual known-good retained revision.

  3. Watch the restored rollout

    The Deployment restores the selected template and coordinates ReplicaSets again. External data and changed-in-place ConfigMaps remain independent.

Revision numbers are illustrative; learners must inspect their own retained history.

Follow the rollout and rollback exercise to watch a healthy update and a failure you can recover from. Check the final image and readiness along with the success message.

Check what rollback can restore

A revision tracks changes to the Pod template. Undoing a Deployment cannot restore a separate ConfigMap, undo a database migration, or put previously deleted data back. Budget spare capacity before choosing a surge strategy. Terminating Pods can also use resources while shutting down. Check whether your readiness probe really proves a Pod can serve the requests the release is meant to handle.

Check your understanding

Five minutes into the release, the old Pods still serve traffic and the first new Pod never became ready. Which evidence would you inspect?

Read the new Pod’s events, conditions, and application logs. These tell you whether the Pod was unable to schedule, unable to start, or failed its readiness probe. Those failures can all look like a stuck Deployment from the outside and require different repairs.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu