In this tutorial, we'll learn how to manage rollouts and rollbacks in Kubernetes. Rollouts and rollbacks are crucial in application deployment as they provide you with the ability to update and revert applications in a Kubernetes cluster without causing downtime.
You will learn how to:
Prerequisites:
- Basic knowledge of Kubernetes
- A running Kubernetes cluster
- kubectl installed and configured to interact with your cluster
In Kubernetes, a Deployment resource is responsible for managing the lifecycle of stateless applications. When you update the Deployment spec, Kubernetes starts a rollout, which is the process of moving from one version of the application to another.
Rollbacks are the process of reverting to a previous version of your application. Kubernetes keeps track of the changes made to the Deployment spec in Revisions. You can rollback to any Revision using a single command.
To monitor the status of a rollout, you can use the kubectl rollout status command followed by the Deployment name.
# Create a Deployment
kubectl create deployment my-app --image=my-app:1.0
# Update the Deployment to a new version
kubectl set image deployment/my-app my-app=my-app:1.1
In the above example, we first create a Deployment named my-app with the image version 1.0. Then, we trigger a rollout by updating the image to 1.1.
# Check the status of the rollout
kubectl rollout status deployment/my-app
The kubectl rollout status command will show the progress of the rollout, and return when the rollout is complete.
# Rollback to the previous version
kubectl rollout undo deployment/my-app
If something goes wrong with version 1.1, you can rollback to the previous version using the kubectl rollout undo command.
In this tutorial, we learned how to manage application rollouts and rollbacks in Kubernetes. We learned how to deploy a new version of an application, monitor the status of the rollout and revert to a previous version if necessary.
To continue learning, you can explore other Kubernetes resources such as Services, and how they interact with Deployments.
Create a new Deployment with an image of your choice. Then, update the Deployment to a new image version. Monitor the status of the rollout.
After the rollout is complete, perform a rollback to the previous version. Check the status of the rollback.
Create two Deployments, each with a different image. Update both Deployments to a new image version simultaneously. Monitor the status of the rollouts, and rollback if necessary.
Remember to practice regularly, and don't be afraid to make mistakes. That's how you learn!