Rolling back a Deployment in Kubernetes is a straightforward process that can be done using the kubectl command-line tool. Here are the steps involved:
View the history of the Deployment: Use the following command to view the history of the Deployment:
kubectl rollout history deployment/<deployment-name>
This command will display a list of revisions for the Deployment, along with information such as the revision number, the date and time of the revision, and any annotations associated with the revision.
Roll back to a specific revision: Once you have identified the revision you want to roll back to, use the following command to initiate the rollback:
kubectl rollout undo deployment/<deployment-name> --to-revision=<revision-number>
This command will initiate a rollback to the specified revision. Kubernetes will automatically update the replicas of the Deployment to the previous version.
Monitor the progress of the rollback: Use the following command to monitor the progress of the rollback:
kubectl rollout status deployment/<deployment-name>
This command will display the status of the Deployment, including the number of replicas that are up and running, and the progress of the rollout.
Verify the rollback: Once the rollback is complete, use the following command to verify that the Deployment has been rolled back to the previous version:
kubectl get deployment/<deployment-name> -o yaml | grep -A 2 image:
This command will display the image tag used by each replica of the Deployment. Verify that the image tag matches the previous version.
Here is an example of rolling back a Deployment to a previous revision:
\# View the history of the Deployment
kubectl rollout history deployment/myapp
\# Roll back to a specific revision
kubectl rollout undo deployment/myapp --to-revision=2
\# Monitor the progress of the rollback
kubectl rollout status deployment/myapp
\# Verify the rollback
kubectl get deployment/myapp -o yaml | grep -A 2 image:
In conclusion, rolling back a Deployment in Kubernetes is a simple process that can be done using the kubectl command-line tool. By following the steps outlined above, you can quickly and easily roll back a Deployment to a previous version.