CKAD — Deployment Rollbacks

2 minute read

Why Rollbacks Matter

Updates can go wrong — a bad image, a misconfigured container, or an application bug. Kubernetes keeps a history of Deployment revisions so you can quickly roll back to a known-good state.

Check Rollout History

kubectl rollout history deployment/web
# Expected:
# REVISION  CHANGE-CAUSE
# 1         <none>
# 2         kubectl set image deployment/web nginx=nginx:1.27

# View details of a specific revision
kubectl rollout history deployment/web --revision=1

Each time you update a Deployment, Kubernetes creates a new revision. The old ReplicaSet is kept (scaled to 0) so it can be restored.

Roll Back to Previous Version

# Roll back to the previous revision
kubectl rollout undo deployment/web

# Roll back to a specific revision
kubectl rollout undo deployment/web --to-revision=1

# Verify the rollback
kubectl rollout status deployment/web
kubectl describe deployment web | grep Image

What Happens During a Rollback

  1. Kubernetes finds the ReplicaSet from the target revision
  2. Scales the old ReplicaSet back up (using rolling update strategy)
  3. Scales the current ReplicaSet down
  4. Creates a new revision number for the rollback

A rollback is essentially a rolling update — back to an old version.

Pause and Resume Rollouts

If you need to make multiple changes before triggering a rollout:

# Pause the rollout
kubectl rollout pause deployment/web

# Make multiple changes — none trigger a rollout while paused
kubectl set image deployment/web nginx=nginx:1.27
kubectl set resources deployment/web -c nginx --limits=cpu=500m,memory=512Mi

# Resume — triggers a single rollout with all changes
kubectl rollout resume deployment/web

Why Pause and Resume?

Without Pause With Pause
Each change triggers a separate rollout All changes applied in one rollout
Multiple Pod restarts Single Pod restart
Intermediate states visible Clean atomic update

Rollout Status

# Check if a rollout is in progress
kubectl rollout status deployment/web

# Possible outputs:
# "deployment "web" successfully rolled out"     ← done
# "Waiting for deployment rollout to finish..."  ← in progress
# Exit code 1                                    ← failed/timed out

# Check with timeout (useful for scripts and exam)
kubectl rollout status deployment/web --timeout=60s

Revision History Limit

By default, Kubernetes keeps the last 10 ReplicaSets (revisions). You can change this:

spec:
  revisionHistoryLimit: 5    # Keep only 5 old ReplicaSets

Setting this to 0 means no rollback capability — old ReplicaSets are deleted immediately.

Rollback Quick Reference

Task Command
View history kubectl rollout history deployment/<name>
View revision details kubectl rollout history deployment/<name> --revision=N
Undo to previous kubectl rollout undo deployment/<name>
Undo to specific revision kubectl rollout undo deployment/<name> --to-revision=N
Pause rollout kubectl rollout pause deployment/<name>
Resume rollout kubectl rollout resume deployment/<name>
Check status kubectl rollout status deployment/<name>

Exam tip: If you push a bad image during the CKAD exam, kubectl rollout undo deployment/<name> is the fastest recovery. Practice the full cycle: update → check → rollback.


Next: Learn operational commands with Managing Deployments →

Updated: