DEV Community

Cover image for 6.Revert Deployment to Previous Version in Kubernetes
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

6.Revert Deployment to Previous Version in Kubernetes

Lab Information

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.

Note: The kubectl utility on jump_host is configured to interact with the Kubernetes cluster.

Lab Solutions

Step 1: Check Current Deployment Status

First, let's check the current state and revision history:

Check current deployment status

kubectl get deployment nginx-deployment
Enter fullscreen mode Exit fullscreen mode

Check current pods and their images

kubectl get pods -l 
Enter fullscreen mode Exit fullscreen mode

Check the rollout history

kubectl rollout history deployment nginx-deployment
Enter fullscreen mode Exit fullscreen mode

Step 2: View Detailed Rollout History

Get detailed revision history with changes

kubectl rollout history deployment nginx-deployment --revision=2
kubectl rollout history deployment nginx-deployment --revision=1
Enter fullscreen mode Exit fullscreen mode

Step 3: Perform the Rollback

Rollback to the previous revision

kubectl rollout undo deployment nginx-deployment
Enter fullscreen mode Exit fullscreen mode

Step 4: Monitor the Rollback

Monitor the rollback progress

kubectl rollout status deployment nginx-deployment --timeout=300s
Enter fullscreen mode Exit fullscreen mode

Watch the pods during rollback

kubectl get pods -l 
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify the Rollback

kubectl get deployment nginx-deployment -o jsonpath='{.spec.template.spec.containers[0].image}' && echo
Enter fullscreen mode Exit fullscreen mode

Check rollout history to confirm rollback

kubectl rollout history deployment nginx-deployment
Enter fullscreen mode Exit fullscreen mode


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)