Values is One of the built-in objects. This object provides access to values passed into the chart. Its contents come from multiple sources:
- The
values.yamlfile in the chart - If this is a subchart, the
values.yamlfile of a parent chart - A values file if passed into helm install or helm upgrade with the -f flag (
helm install -f myvals.yaml ./mychart) - Individual parameters passed with
--set(such ashelm install --set foo=bar ./mychart)
The list above is in order of specificity: values.yaml is the default, which can be overridden by a parent chart’s values.yaml, which can in turn be overridden by a user-supplied values file, which can in turn be overridden by --set parameters.
Values files are plain YAML files. Let’s edit mychart/values.yaml and then edit our ConfigMap template.
Removing the defaults in values.yaml, we’ll set just one parameter:
favoriteDrink: coffeeNow we can use this inside of a template:
apiVersion: v1kind: ConfigMapmetadata: name: {{ .Release.Name }}-configmapdata: myvalue: "Hello World" drink: {{ .Values.favoriteDrink }}Notice on the last line we access favoriteDrink as an attribute of Values: {{ .Values.favoriteDrink }}.
Let’s see how this renders.
$ helm install geared-marsupi ./mychart --dry-run --debuginstall.go:158: [debug] Original chart version: ""install.go:175: [debug] CHART PATH: /home/bagratte/src/playground/mychart
NAME: geared-marsupiLAST DEPLOYED: Wed Feb 19 23:21:13 2020NAMESPACE: defaultSTATUS: pending-installREVISION: 1TEST SUITE: NoneUSER-SUPPLIED VALUES:{}
COMPUTED VALUES:favoriteDrink: coffee
HOOKS:MANIFEST:---# Source: mychart/templates/configmap.yamlapiVersion: v1kind: ConfigMapmetadata: name: geared-marsupi-configmapdata: myvalue: "Hello World" drink: coffeeBecause favoriteDrink is set in the default values.yaml file to coffee, that’s the value displayed in the template. We can easily override that by adding a --set flag in our call to helm install:
$ helm install solid-vulture ./mychart --dry-run --debug --set favoriteDrink=slurminstall.go:158: [debug] Original chart version: ""install.go:175: [debug] CHART PATH: /home/bagratte/src/playground/mychart
NAME: solid-vultureLAST DEPLOYED: Wed Feb 19 23:25:54 2020NAMESPACE: defaultSTATUS: pending-installREVISION: 1TEST SUITE: NoneUSER-SUPPLIED VALUES:favoriteDrink: slurm
COMPUTED VALUES:favoriteDrink: slurm
HOOKS:MANIFEST:---# Source: mychart/templates/configmap.yamlapiVersion: v1kind: ConfigMapmetadata: name: solid-vulture-configmapdata: myvalue: "Hello World" drink: slurmSince --set has a higher precedence than the default values.yaml file, our template generates drink: slurm.
Values files can contain more structured content, too. For example, we could create a favorite section in our values.yaml file, and then add several keys there:
favorite: drink: coffee food: pizzaNow we would have to modify the template slightly:
apiVersion: v1kind: ConfigMapmetadata: name: {{ .Release.Name }}-configmapdata: myvalue: "Hello World" drink: {{ .Values.favorite.drink }} food: {{ .Values.favorite.food }}While structuring data this way is possible, the recommendation is that you keep your values trees shallow, favoring flatness. When we look at assigning values to subcharts, we’ll see how values are named using a tree structure.