Helm Chart Rollback


Helm Chart Rollback

In this tutorial, we are going to discuss about how to rollback helm chart in Kubernetes cluster. Here I’m going to use the project that we used earlier for upgrade.

Let me go ahead and do an another upgrade. Before that let me check, What are all the revisions available helm history and name of the deployment.

ashok@waytoeasylearn:~$ helm history install-upgrade-rollback-demo
REVISION        UPDATED                         STATUS          CHART                   APP VERSION     DESCRIPTION     
1               Sat May 29 17:41:28 2021        superseded      upgrade-rollback-0.1.0  1.16.0          Install complete
2               Sun May 30 17:20:05 2021        deployed        upgrade-rollback-0.2.0  1.16.0          Upgrade complete

So I do have two revisions, in that the revision two is deployed and the revision 1 is superseded. Now, I’m going to make another revision. Let me go ahead and make changes to the values.yaml file. I’m making the replica count as 3.

ashok@waytoeasylearn:~$ cat upgrade-rollback/values.yaml 
# Default values for upgrade-rollback.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 3
image:
  repository: nginx
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: ""
................
................
................

Now, let me go ahead and make changes to the chart.yaml file. I’m going to make change to the description. And change the version say I want to make this particular version as 0.3.0.

ashok@waytoeasylearn:~$ cat upgrade-rollback/Chart.yaml 
apiVersion: v2
name: upgrade-rollback
description: A helm chart with 3 PODS
type: application
version: 0.3.0
appVersion: "1.16.0"

Now, I’m going to push this change into the repo, without pushing into the repo directly I can deploy the chart. But to understand the standard way of deployment I’m pushing it into the repository.

ashok@waytoeasylearn:~$ helm push upgrade-rollback/ mychartmuseumrepo
Pushing upgrade-rollback-0.3.0.tgz to mychartmuseumrepo…
Done.

Then to check whether it is available before that I need to do the upgrade and search the repository using helm search command

ashok@waytoeasylearn:~$ helm repo update
Hang tight while we grab the latest from your chart repositories…
…Successfully got an update from the "mychartmuseumrepo" chart repository
…Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈

ashok@waytoeasylearn:~$ helm search repo mychartmuseumrepo -l
NAME                                    CHART VERSION   APP VERSION     DESCRIPTION                                  
mychartmuseumrepo/helmpushdemo          0.1.0           1.16.0          Helm push plugin demo                        
mychartmuseumrepo/myrepo                0.1.0           1.16.0          My another helm chart                        
mychartmuseumrepo/repotest              0.1.1           1.16.0          Repo demo in helm using ChartMuseum to 0.1.1 
mychartmuseumrepo/repotest              0.1.0           1.16.0          Repo demo in helm using ChartMuseum          
mychartmuseumrepo/upgrade-rollback      0.3.0           1.16.0          A helm chart with 3 PODS                     
mychartmuseumrepo/upgrade-rollback      0.1.0           1.16.0          A Helm chart for upgrade and rollback details

Here I do have the latest version that we pushed into the repository that is 0.3.0. Now I’m going to upgrade the helm deployment. Let me check what are all the deployments available

ashok@waytoeasylearn:~$ helm list
NAME                            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
install-upgrade-rollback-demo   default         2               2021-05-30 17:20:05.063549035 +0530 IST deployed        upgrade-rollback-0.2.0  1.16.0     

So this is the deployment and the revision that is running is 2.

Upgrade Helm chart

I’m going to do an upgrade.

ashok@waytoeasylearn:~$ helm upgrade install-upgrade-rollback-demo mychartmuseumrepo/upgrade-rollback
Release "install-upgrade-rollback-demo" has been upgraded. Happy Helming!
NAME: install-upgrade-rollback-demo
LAST DEPLOYED: Mon May 31 10:49:51 2021
NAMESPACE: default
STATUS: deployed
REVISION: 3
NOTES:
Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=upgrade-rollback,app.kubernetes.io/instance=install-upgrade-rollback-demo" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT 

So did the deployment and the revision got changed to 3. Now I can check helm list.

ashok@waytoeasylearn:~$ helm list
NAME                            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
install-upgrade-rollback-demo   default         3               2021-05-31 10:49:51.219707811 +0530 IST deployed        upgrade-rollback-0.3.0  1.16.0     

So the revision that is running is 3. I can get the entire history of the helm deployment.

ashok@waytoeasylearn:~$ helm history install-upgrade-rollback-demo
REVISION        UPDATED                         STATUS          CHART                   APP VERSION     DESCRIPTION     
1               Sat May 29 17:41:28 2021        superseded      upgrade-rollback-0.1.0  1.16.0          Install complete
2               Sun May 30 17:20:05 2021        superseded      upgrade-rollback-0.2.0  1.16.0          Upgrade complete
3               Mon May 31 10:49:51 2021        deployed        upgrade-rollback-0.3.0  1.16.0          Upgrade complete

So here I do have three revisions. Now the version that is running is 3. I can confirm using kubectl command,

ashok@waytoeasylearn:~$ kubectl get all
NAME                                                READY   STATUS    RESTARTS   AGE
pod/install-upgrade-rollback-demo-994c4df47-9dxpw   1/1     Running   3          41h
pod/install-upgrade-rollback-demo-994c4df47-lqqdz   1/1     Running   2          18h
pod/install-upgrade-rollback-demo-994c4df47-f5qsx   1/1     Running   0          31m

NAME                                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
service/kubernetes                      ClusterIP   10.152.183.1             443/TCP   10d
service/install-upgrade-rollback-demo   ClusterIP   10.152.183.182           80/TCP    41h
NAME                                            READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/install-upgrade-rollback-demo   3/3     3            3           41h

NAME                                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/install-upgrade-rollback-demo-994c4df47   3         3         3       41h

So I do have 3 pods running.

Rollback Helm chart

Now For some reason I realized this particular revision is not good. So I wanted to roll back to the revision 2. Now I can use the command helm rollback and name of the deployment and the revision that I wanted to rollback to.

ashok@waytoeasylearn:~$ helm rollback install-upgrade-rollback-demo 2
Rollback was a success! Happy Helming!

So the rollback is success. Now I can go ahead and check the history of this specific deployment

ashok@waytoeasylearn:~$ helm history install-upgrade-rollback-demo
 REVISION        UPDATED                         STATUS          CHART                   APP VERSION     DESCRIPTION     
 1               Sat May 29 17:41:28 2021        superseded      upgrade-rollback-0.1.0  1.16.0          Install complete
 2               Sun May 30 17:20:05 2021        superseded      upgrade-rollback-0.2.0  1.16.0          Upgrade complete
 3               Mon May 31 10:49:51 2021        superseded      upgrade-rollback-0.3.0  1.16.0          Upgrade complete
 4               Mon May 31 11:24:30 2021        deployed        upgrade-rollback-0.2.0  1.16.0          Rollback to 2   

And I do have the revision 4 and the revision four is rollbacked to 2. So the revision that is deployed is 4 and that got rolled back to the revision 2 and within revision 2 we had 2 pods. So I can go ahead and check whether 2 pods are running

ashok@waytoeasylearn:~$ kubectl get all
NAME                                                READY   STATUS    RESTARTS   AGE
pod/install-upgrade-rollback-demo-994c4df47-9dxpw   1/1     Running   3          41h
pod/install-upgrade-rollback-demo-994c4df47-lqqdz   1/1     Running   2          18h

NAME                                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
service/kubernetes                      ClusterIP   10.152.183.1             443/TCP   10d
service/install-upgrade-rollback-demo   ClusterIP   10.152.183.182           80/TCP    41h

NAME                                            READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/install-upgrade-rollback-demo   2/2     2            2           41h

NAME                                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/install-upgrade-rollback-demo-994c4df47   2         2         2       41h

Here I do have only 2 pods. So automatically it went ahead and made the changes to the required number of PODs. So this is going to prove how easy it is to upgrade or rollback any deployment using helm package manager.

And this is one of the biggest advantage and that’s where helm is going to have the edge.

So in a quick summary we have seen how to do the upgrade and rollback of a deployment using helm.

Helm Chart Rollback
Scroll to top