Kubernetes Deployments handle rollbacks by maintaining a history of previous ReplicaSets associated with the Deployment. When you update a Deployment, Kubernetes creates a new ReplicaSet for the updated version while keeping the old ReplicaSet intact. If the new version encounters issues, you can easily rollback to a previous version using the following steps:
-
Rollback Command: Use the
kubectl rollout undocommand to revert to the previous ReplicaSet. For example:kubectl rollout undo deployment/<deployment-name> -
Check Rollback Status: You can check the status of the rollback using:
kubectl rollout status deployment/<deployment-name> -
Revision History: Kubernetes keeps track of the revision history of the Deployment, allowing you to specify a specific revision to rollback to if needed:
kubectl rollout undo deployment/<deployment-name> --to-revision=<revision-number>
This mechanism ensures that you can quickly revert to a stable version of your application if a deployment fails or causes issues.
