94

Can I have multiple values.yaml files in a Helm chart?

Something like mychart/templates/internalValues.yaml, mychart/templates/customSettings.yaml, etc?

Accessing properties in a values.yaml file can be done by {{ .Values.property1 }}. How would I reference the properties in these custom values.yaml files?

Ethan Strider
  • 7,849
  • 3
  • 24
  • 29
James Isaac
  • 2,587
  • 6
  • 20
  • 30

3 Answers3

143

Yes, it's possible to have multiple values files with Helm. Just use the --values flag (or -f).

Example:

helm install ./path --values ./internalValues.yaml --values ./customSettings.yaml

You can also pass in a single value using --set.

Example:

helm install ./path --set username=ADMIN --set password=${PASSWORD}

From the official documentation:

There are two ways to pass configuration data during install:

--values (or -f): Specify a YAML file with overrides. This can be specified multiple times and the rightmost file will take precedence

--set (and its variants --set-string and --set-file): Specify overrides on the command line.

If both are used, --set values are merged into --values with higher precedence. Overrides specified with --set are persisted in a configmap. Values that have been --set can be viewed for a given release with helm get values . Values that have been --set can be cleared by running helm upgrade with --reset-values specified.

Ethan Strider
  • 7,849
  • 3
  • 24
  • 29
  • 11
    Just wanted to note that specifying multiple value files does not merge values which are present in these files which was discussed here: [Helm should preform deep merge on multiple values files](https://github.com/helm/helm/issues/3486) – brass monkey Jan 15 '20 at 16:33
  • Link to documentation is broken. – Marcel Jan 25 '22 at 12:56
  • 1
    Thanks @Marcel, updated the link. – Ethan Strider Feb 01 '22 at 19:45
  • 3
    @EthanStrider is this still the case? I just tried it and it does merge all the values from multiple values files. I have values.yaml and values-dev.yaml and the end result has all the variables from both files with the last specified file overriding the values from the first file. Simple example from official docs https://helm.sh/docs/chart_template_guide/values_files/ – Tudor Feb 09 '22 at 23:51
  • FYI, the provided doc link no longer seems to contain the quoted info on multiple values files. That info seems to have moved here: https://helm.sh/docs/helm/helm_install/#synopsis – Seth May 10 '23 at 19:06
78

Helm by default will only use the values.yaml file in the root directory of your chart.

You can ask it to load additional values files when you install. For instance, if you have any settings that point to different databases in different environments:

helm install . -f values.production.yaml

You could also get a similar effect by bundling additional settings as a file, and asking Helm to read the bundled file. Helm provides an undocumented fromYaml template function which can parse the file, so in principle you can do something like

{{- $v := $.Files.Get "more-values.yaml" | fromYaml }}
foo: {{ $v.bar }}
Mark_Eng
  • 443
  • 1
  • 4
  • 12
David Maze
  • 130,717
  • 29
  • 175
  • 215
  • 3
    Specifically, this is what worked for me: {{- $v := (.Files.Get "internalvalues.yaml") | fromYaml }} – James Isaac Jul 02 '18 at 07:35
  • Also, I put my file directly under the chart directory. – James Isaac Jul 02 '18 at 07:37
  • Woud this be the case if you wanted to run two version of the application? For instance, say I wanted to launch two instances of an nginx container, but one displayed "hello" and the other displayed "Hola", using two different values files inside the same chart, could you launch "nginx1" and nginx2" with two different values? – Evan R. Dec 20 '18 at 04:07
  • @JamesIsaac where did you put that snippet? In my use case I am writing an umbrella chart but I don't want to put all the config for all the subcharts in the same values.yaml. – David Ham Mar 12 '19 at 15:28
  • I used it for a single helm chart and not an umbrella helm chart. I had placed the snippet at the top of the yaml file. – James Isaac Mar 20 '19 at 07:50
  • `{{- $v := $.Files.Get "more-values.yaml" | fromYaml }} foo: {{ $v.bar }}` where to write this in deployment or where ? – cloudbud Oct 08 '19 at 09:42
  • @DavidHam how did you solve the problem of umbrella chart? – Duc Le Jul 02 '21 at 04:36
  • i'm trying to apply it like so, but my configuration has nested yaml inside: ``` config: | {{- $v := $.Files.Get "config.yaml" | fromYaml }} {{- range $key, $value := $v.config }} {{ $key }} = {{ tpl $value $ }} {{- end }} ``` – petroslamb Sep 28 '21 at 22:13
9

Just to update : As per the current official documentation --set & --values will not be merged

To override values in a chart, use either the '--values' flag and pass in a file or use the '--set' flag and pass configuration from the command line, to force a string value use '--set-string'. In case a value is large and therefore you want not to use neither '--values' nor '--set', use '--set-file' to read the single large value from file.

Also :

You can specify the '--values'/'-f' flag multiple times. The priority will be given to the last (right-most) file specified.

ak89224
  • 151
  • 1
  • 5
  • I just tried it and it DOES merge all the values-*.yaml files that I specify. Try it too from the official docs. https://helm.sh/docs/chart_template_guide/values_files/ – Tudor Feb 09 '22 at 23:54
  • 1
    The docs don't state that files will not be merged. Instead the second part you cited has another sentence after it that makes it more clear: "For example, if both myvalues.yaml and override.yaml contained a key called 'Test', the value set in override.yaml would take precedence" – fantaztig May 03 '22 at 11:41