0
0
Kubernetesdevops~5 mins

Rollback to previous version in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes a new version of your app causes problems. Rollback lets you quickly go back to the last working version to keep your app running smoothly.
When a new deployment causes errors or crashes in your app
When you want to undo a recent update that broke functionality
When you need to quickly restore service after a failed rollout
When testing a new version and deciding to revert to stable
When a configuration change causes unexpected behavior
Commands
This command rolls back the deployment named 'example-deployment' to its previous version to fix issues caused by the latest update.
Terminal
kubectl rollout undo deployment/example-deployment
Expected OutputExpected
deployment.apps/example-deployment rolled back
This command checks the status of the rollback to confirm the deployment is successfully restored to the previous version.
Terminal
kubectl rollout status deployment/example-deployment
Expected OutputExpected
deployment "example-deployment" successfully rolled out
This command shows the current state of the deployment after rollback, including the number of pods running the previous version.
Terminal
kubectl get deployment example-deployment
Expected OutputExpected
NAME READY UP-TO-DATE AVAILABLE AGE example-deployment 3/3 3 3 10m
Key Concept

If you remember nothing else from this pattern, remember: kubectl rollout undo lets you quickly revert to the last working deployment version.

Common Mistakes
Trying to rollback a deployment that has no previous revision
Rollback fails because there is no earlier version to revert to.
Make sure the deployment has at least one previous revision before running rollback.
Not checking rollout status after rollback
You might miss that the rollback failed or is still in progress.
Always run 'kubectl rollout status' to confirm the rollback completed successfully.
Using incorrect deployment name in the rollback command
The command fails because Kubernetes cannot find the deployment.
Verify the deployment name with 'kubectl get deployments' before rolling back.
Summary
Use 'kubectl rollout undo deployment/example-deployment' to revert to the previous deployment version.
Check rollback progress with 'kubectl rollout status deployment/example-deployment'.
Verify the deployment state with 'kubectl get deployment example-deployment' after rollback.