Set values to templates
In this tutorial, we are going to discuss about set values to templates in Kubernetes. Let us understand how to change the default value from the values.yaml file when the release is getting released.
Let us use the same example. I do have the values.yaml file. Let me go ahead and do a dry run, and I want to replace the message with some other value.
So I can use the set flag helm install dry run. I want to run it in the debug mode and I’m going to set the key message to “Hello world” and the name of the release is valueset and the chart resources to use from this specific folder.
[email protected]:~$ helm install --dry-run --debug --set message="Hello world" valueset ./mychart install.go:173: [debug] Original chart version: "" install.go:190: [debug] CHART PATH: /home/ashok/mychart NAME: valueset LAST DEPLOYED: Tue May 18 17:23:50 2021 NAMESPACE: default STATUS: pending-install REVISION: 1 TEST SUITE: None USER-SUPPLIED VALUES: message: Hello world COMPUTED VALUES: message: Hello world HOOKS: MANIFEST: Source: mychart/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: valueset-configmap data: myvalue: "Sample Config Map" message: Hello world
So what’s going to do when the template is getting generated, the value will be computed from the values.yaml file and if any value is set within the command prompt, the set is going to get more precedence.
So what will happen, the value provided over command prompt will be replaced within the computed values file and that will be replaced within the templates.
Here “Hello world” is the computed value. The reason, because the user supplied this specific value using this set command and “Welcome to waytoeasylearn” got replaced and Hello world is the final computed value.
I may want to do a release with some custom value, and I don’t want to use that default value, for that particular purpose I can use this specific set option.
Set option in helm install
And doing the installation also I can use the set. Let me go ahead and do the installation
[email protected]:~$ helm install valueset ./mychart/ --set message="Hello world" NAME: valueset LAST DEPLOYED: Tue May 18 16:59:52 2021 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None
It is done. Let me go ahead and get the manifest using the release name.
[email protected]:~$ helm get manifest valueset --- # Source: mychart/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: valueset-configmap data: myvalue: "Sample Config Map" message: Hello world
So here it is using the new value that we provided as a part of the command prompt.
[email protected]:~$ kubectl describe configmaps valueset-configmap Name: valueset-configmap Namespace: default Labels: app.kubernetes.io/managed-by=Helm Annotations: meta.helm.sh/release-name: valueset meta.helm.sh/release-namespace: default Data ==== message: ---- Hello world myvalue: ---- Sample Config Map Events:
So I can change the value thats provided as a part of the values.yaml file as well during the deployment.
This I will be using it whenever I wanted to do any custom deployment and change the value only for that specific release.
So in a quick summary we have discussed how to use the set flag as a part of the command prompt to change the values provided by the values.yaml file.