Set values to templates


Set values to templates

In this tutorial, we are going to discuss 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.

Set values to templates

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.

ashok@waytoeasylearn:~$ 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 will get more precedence.

So what will happen? The value provided over the command prompt will be replaced within the computed values file, and that will replace 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; I can use this specific set option for that particular purpose.

Set option in helm install

And doing the installation also I can use the set. Let me go ahead and do the installation.

ashok@waytoeasylearn:~$ 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.

ashok@waytoeasylearn:~$ 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.

So this would have done a deployment of ConfigMaps. I can check the value of the config map as well within the ConfigMap.

ashok@waytoeasylearn:~$ 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 that’s provided as a part of the values.yaml file as well during the deployment.

I will use it whenever I want to do any custom deployment and change the value only for that release.

Summary

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.

Set values to templates
Scroll to top