Chart Template


Chart Template

In this tutorial, how to start building our own chart template. In the previous tutorial we discussed about 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 is charts, templates and other YAML files. That’s going to be the core file, which is going to have the entire description about this particular chart and values.yaml file.

Within 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’m going to create a config map, config map is nothing but an entity within Kubernetes, which is going to hold 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’m going to create the API version, kind, metadata and the data required for this particular config map. This is a very simple 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 next 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 so that we can deploy this particular chart and check whether the entire workflow is working fine or not.

So I do have the config map where I do 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 am going to 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 that 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 just to make sure that particular config map does not exist.

[email protected]:~$ kubectl describe configmaps mychart-configmap
Error from server (NotFound): configmaps "mychart-configmap" not found

This is to double confirm this particular config map is not existing within the Kubernetes cluster. So here I do not have this particular config map.

Now, I am going to install the chart so the command is helm install and name of the chart. I’ll give it as helm-demo-configmap and then the folder where I do have the resources required for this particular chart.

[email protected]:~$ 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 is going to 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 it later.

List helm

Now, let me go ahead and list the entities available using the following command.

[email protected]:~$ 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.

[email protected]:~$ 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 do have a config map that got deployed with the key myvalue and the value sample config map. So this is our 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 name of the chart.

[email protected]:~$ 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.

[email protected]:~$ kubectl describe configmaps mychart-configmap
Error from server (NotFound): configmaps "mychart-configmap" not found

[email protected]:~$ helm ls
NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION

So that is also removed from the Kubernetes cluster. And within 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 as well using uninstall.

Chart Template


Scroll to top