Helm Chart Upgrade
In this tutorial, we are going to discuss about how to upgrade helm chart in Kubernetes cluster. Once the chart is created, I can directly deploy the charts into the Kubernetes cluster as well as do the other managements like upgrade and rollback.
And in case, if I wanted more management, I can add the charts as a part of the repository and do the deployment from the repository or I can use some CI/CD tools to pick the charts from the repository and deploy them into the Kubernetes cluster.
Already we had seen how to add chart as a part of the repository and deploy them. Now we are going to concentrate on the lifecycle of the charts within the Kubernetes cluster. That is installation, upgrade and rollback.
Example
First, let’s go ahead and create a sample chart. I am going to create a chart with the name upgrade-rollback.
ashok@waytoeasylearn:~$ helm create upgrade-rollback
Creating upgrade-rollback
The folder should get created. If I get into the specific folder, I should have a set of templates, chart.yaml and values.yaml. And within templates, as we discussed earlier, it’s going to have some sample deployments, services, ingress details.
I’m going to deploy it as it is, I’m going to modify the description within the chart.yaml file. I’ll add some details to the description.
ashok@waytoeasylearn:~$ cat upgrade-rollback/Chart.yaml
apiVersion: v2
name: upgrade-rollback
description: A Helm chart for upgrade and rollback details
type: application
version: 0.1.0
appVersion: "1.16.0"
Now, I do have the chart. Now I’m going to push this chart into the repository.
ashok@waytoeasylearn:~$ helm push upgrade-rollback/ mychartmuseumrepo
Pushing upgrade-rollback-0.1.0.tgz to mychartmuseumrepo…
Done.
So I’ll be using helm push and the folder and the name of the repository. So it is pushed and I need to update the local cache. This is little confusing for those who are new to git. This looks very similar to the local git repository and the remote git repository.
Whenever I’m going to do the push the data going to get added into the remote repository and I need to update my local cache as well. Otherwise, I will not be in a position to get any repository using the search.
Now without doing the update I am doing the search. So it should not list any charts.
ashok@waytoeasylearn:~$ helm search repo mychartmuseumrepo
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
Now I can go ahead and do an update.
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!⎈
So update what it will do it will connect to the server url and the port and check Is there any new updates available and it’s going to pull the details. So it got an update from this particular repository.
ashok@waytoeasylearn:~$ helm search repo mychartmuseumrepo
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/upgrade-rollback 0.1.0 1.16.0 A Helm chart for upgrade and rollback details
Install Chart
Now I’m going to install this particular chart into the Kubernetes cluster. Let me go ahead and do the installation.
ashok@waytoeasylearn:~$ helm install install-upgrade-rollback-demo upgrade-rollback/
NAME: install-upgrade-rollback-demo
LAST DEPLOYED: Sat May 29 17:41:28 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
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
Now I can get the details about the entities that got deployed within the Kubernetes cluster by using the kubectl get all command. This command will give information about all required pods, services, deployments, replica sets it got deployed.
I can get the details about the deployments using helm list
ashok@waytoeasylearn:~$ helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
install-upgrade-rollback-demo default 1 2021-05-29 17:41:28.165721592 +0530 IST deployed upgrade-rollback-0.1.0 1.16.0
So I do have one deployment and the revision is 1. When it got deployed, I do have the details and the status is deployed.
Now, I’m going to make changes to that specific chart. Let me get into the chart folder. I wanted to make replicaCount as 2. So what I did I modified the values file and changed the replica count to 2. So it should deploy two pods.
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: 2
image:
repository: nginx
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
................
................
................
And I’m going to modify the chart.yaml file because we’ve made change. And I’m going to add some description and I’ll be making change to the version as well.
ashok@waytoeasylearn:~$ cat upgrade-rollback/Chart.yaml
apiVersion: v2
name: upgrade-rollback
description: A New version Helm chart for upgrade and rollback details
type: application
version: 0.2.0
appVersion: "1.16.0"
Upgrade Deployment
So I have made the version as 0.2.0. Now, I am going to upgrade this particular deployment using helm upgrade
ashok@waytoeasylearn:~$ helm upgrade install-upgrade-rollback-demo upgrade-rollback/
NAME: install-upgrade-rollback-demo
LAST DEPLOYED: Sun May 30 17:20:05 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
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 it’s going to identify only the delta. This is the very important benefit of having helm package manager where it’s going to identify what change or what is the delta between the earlier version and the new version.
It’s going to make another revision into the deployment and it’ll make only that specific changes into the deployment and it will not disturb the other entities within the Kubernetes cluster.
Now, let me go ahead and get all the entities running as a part of Kubernetes.
ashok@waytoeasylearn:~$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/install-upgrade-rollback-demo-994c4df47-9dxpw 1/1 Running 1 23h
pod/install-upgrade-rollback-demo-994c4df47-lqqdz 1/1 Running 0 13m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.152.183.1 443/TCP 9d
service/install-upgrade-rollback-demo ClusterIP 10.152.183.182 80/TCP 23h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/install-upgrade-rollback-demo 2/2 2 2 23h
NAME DESIRED CURRENT READY AGE
replicaset.apps/install-upgrade-rollback-demo-994c4df47 2 2 2 23h
It went ahead and deployed two PODs. So I do have 2 PODs as a part of the deployment and both the PODs are up and running. Now you can realize how easy it is to upgrade the Kubernetes entities using the helm.
This is the biggest advantage and I don’t need to touch any of the templates or any of the manifest file of Kubernetes. All I did was changed only the values file.
So within the charts I updated the values file for 2 replica counts. The same way all the values that are mentioned as a part of the value files can be configured and in a quick deployment, I can go ahead and do the upgrade.
In case if I wanted to get the entire history about what all things got deployed as a part of the helm, I can go ahead and use the following command
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 here I do have two revisions and revision 1 is superseded, revision 2 is deployed. The one that is running is revision 2.
Summary
So in a quick summary, we have seen how to install a chart and do the upgrade and how easy it is using the helm chart.