Introduction
Rolling Updates and Rollbacks are crucial parts of Application Lifecycle Management (ALM) in Kubernetes. Kubernetes is an open-source container orchestration tool that simplifies the application deployment process. Updating applications to a new version with zero downtime is crucial in today's fast-paced development lifecycle. In this blog, we will discuss Rolling Updates and Rollbacks in Kubernetes, including how to perform them and the benefits.
Rolling Updates
A Rolling Update is a process of updating an application by incrementally updating its replicas, one by one, while ensuring no downtime. Rolling updates are crucial in the maintenance of applications since they enable organizations to roll out updates efficiently and incrementally.
How to perform Rolling Updates in Kubernetes?
In Kubernetes, updates to an application can be done using a simple update to the deployment manifest. The following is an example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: my-image:v2
ports:
- containerPort: 80
The above deployment manifest describes a simple deployment. When an update is needed, Kubernetes understands that it needs to roll out to a new version of the image. Suppose the image version is v3. In that case, a simple command like the following will commence the Rolling Update process:
$ kubectl set image deployment/my-app-deployment my-app-container=my-image:v3
Here, Kubernetes understands that an update has been made in V3, and it gradually begins to upgrade replicas of the previous image one by one. Kubernetes scales down the number of replicas of the previous and scales up replicas of the new version, gradually moving to full use of the new version.
Rollbacks
Rollback is the process of reinstalling the previous application version when an update goes wrong. For instance, when errors occur on the new version, Rollback ensures that the working version is reinstalled immediately while minimizing application downtime.
How to perform Rollbacks in Kubernetes?
Kubernetes supports Rollback with a built-in feature. When making a change within a deployment, Kubernetes tracks the history of changes. Thus, performing a typical command to view deployment history reveals the history:
$ kubectl rollout history deployment/my-app-deployment
The history provides an overview of the Rollout revisions. To Rollback to previous revisions, the following command performs the previous deployment's rollback:
$ kubectl rollout undo deployment/my-app-deployment --to-revision=2
The above command rolls back to the previous version through the parameter --to-revision
set to the required revision.
Conclusion
Rolling updates and Rollbacks are essential tools for Application Lifecycle Management in Kubernetes. Kubernetes provides a robust set of tools that allow organizations to perform updates seamlessly, minimizing downtimes and enabling fast-paced development on modern-day DevOps engineering practices. Organizations should invest in understanding and include these features while deploying in Kubernetes for efficient and smooth rollouts.