Helm Chart Template
In this tutorial, we will discuss how to start building our helm chart template. In the previous tutorial, we discussed how to create the file structure using the chart create command.
And we created the folder, mychart. So within mychart, we do have these folders That are charts, templates and other YAML files. That will be the core file, which will have the full description of this particular chart and values.yaml file.
Within the templates file, we have some sample templates. We went ahead and deleted them. So there should not be any template within it.
Now within this, I will create a config map; A config map is nothing but an entity within Kubernetes, holding a key-value pair. And that will be used by other entities to read the values corresponding to the key.
Sample Example
Let me go ahead and create a sample YAML file. Within this, I will create the API version, kind, metadata and the data required for this particular config map. This is a straightforward file.
apiVersion: v1
kind: ConfigMap
metadata:
name: mychart-configmap
data:
myvalue: "Sample Config Map"
This is the starting point where I will be creating a config map, and in the following tutorial, I’m going to introduce how to insert a template language and read the values from the value file.
So don’t worry; this is just to get started to deploy this particular chart and check whether the entire workflow is working fine or not.
So I have the config map where I have the key value, myvalue as the key, and “Sample config map” is the value corresponding to it.
This will be creating a config map with the name mychart-config map. I can use the kubectl command to create the config map, but I will use the chart to deploy this particular config map into the cluster.
Install helm chart
So I updated a YAML file within the templates, and the folder we’re using is mychart. Now I’m going to install this particular mychart with the name helm-demo-config-map.
Before that, let me go ahead and list the config maps available. I can use the kubectl describe command config maps and the name of the config map to make sure that particular config map does not exist.
ashok@waytoeasylearn:~$ kubectl describe configmaps mychart-configmap
Error from server (NotFound): configmaps "mychart-configmap" not found
This is to confirm double this particular config map is not existing within the Kubernetes cluster. So here, I do not have this particular config map.
Now, I will install the chart, so the command is helm install and the chart’s name. I’ll give it helm-demo-configmap and then the folder where I have the resources required for this chart.
ashok@waytoeasylearn:~$ helm install helm-demo-configmap ./mychart
NAME: helm-demo-configmap
LAST DEPLOYED: Sun May 16 17:42:20 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
So this will create the config map and the status it is saying deployed, and the revision that it’s deployed is 1.
Now let’s concentrate on how to build this particular chart. The other details like test suite, revision all this we will be discussing later.
List helm
Now, let me go ahead and list the entities available using the following command.
ashok@waytoeasylearn:~$ helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
helm-demo-configmap default 1 2021-05-16 17:42:20.950283008 +0530 IST deployed mychart-0.1.0 1.16.0
So I do have this particular chart deployed, and the version that got deployed is 1. Now, let me go ahead and describe the config map.
ashok@waytoeasylearn:~$ kubectl describe configmaps mychart-configmap
Name: mychart-configmap
Namespace: default
Labels: app.kubernetes.io/managed-by=Helm
Annotations: meta.helm.sh/release-name: helm-demo-configmap
meta.helm.sh/release-namespace: default
Data
myvalue:
Sample Config Map
Events: <none>
Yes, I have a config map deployed with the key myvalue and the value sample config map. So this is the first successful chart that we had created.
And from here, we are going to develop and start introducing the templatizing of this particular YAML file and start using the values file.
Let me go ahead and uninstall this particular config map and keep the system clean using the command helm uninstall and then the chart’s name.
ashok@waytoeasylearn:~$ helm uninstall helm-demo-configmap
release "helm-demo-configmap" uninstalled
So the chart will get uninstalled, and all the entities related to this particular chart will also get removed from the Kubernetes cluster.
I can confirm that by describing the config map.
ashok@waytoeasylearn:~$ kubectl describe configmaps mychart-configmap
Error from server (NotFound): configmaps "mychart-configmap" not found
ashok@waytoeasylearn:~$ helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
So that is also removed from the Kubernetes cluster. And within the helm, I should not have the release related to this particular chart.
Conclusion
So in a quick summary, we have seen how to create a chart and update the template folder and install the chart using the helm install and, after installation, how to remove them using uninstall.