Execute Rollback in Kubernetes Cluster
Earlier today, the Nautilus DevOps team deployed a new release for an application. However, a customer has reported a bug related to this recent release. Consequently, the team aims to revert to the previous version.
- There exists a deployment named nginx-deployment; initiate a rollback to the previous revision.
Steps
-
Let’s see the deployments and pods
kubectl get deployments.apps
kubectl get pods
-
Let’s see current container image version
kubectl describe pods pod-name
-
To roll back the deployment to our last working version, we can use the following command:
kubectl rollout undo deployments/nginx-deployment
It will move back to prevous version of deployments
Good to Know?
Rollback Operations
- Purpose: Revert to previous working version
- Revision History: Kubernetes maintains deployment history
- Quick Recovery: Fast recovery from failed deployments
- Automatic: Can be triggered by failed health checks
Rollback Commands
- Undo:
kubectl rollout undo deployment/name
- Specific Revision:
kubectl rollout undo deployment/name --to-revision=2
- History:
kubectl rollout history deployment/name
- Revision Details:
kubectl rollout history deployment/name --revision=3
Revision Management
- Revision Limit: Configure
revisionHistoryLimit
- Change Cause: Use
--record flag to track changes
- Annotations: Kubernetes tracks change causes
- Cleanup: Old ReplicaSets are retained for rollback
Rollback Scenarios
- Failed Deployment: Application not starting correctly
- Performance Issues: New version causing problems
- Bug Discovery: Critical bugs found in production
- Configuration Errors: Incorrect environment variables