Search code examples
kubernetes-helm

Import a value from a common source to multiple values.yml in helm


I'm in a situation where I have multiple values-*.yml files that are intended to configure multiple instances of an app, and all of them configure an env variable with the version of a plugin in this way:

# values-myapp1.yaml
env:
  - name: PLUGIN_VERSION
    value: 0.0.0
  - ...
# values-myapp2.yaml
env:
  - name: PLUGIN_VERSION
    value: 0.0.0
  - ...
# values-myapp3.yaml
env:
  - name: PLUGIN_VERSION
    value: 0.0.0
  - ...

...

And whenever I want to update this version I am required to change all the files. Is there any way to centralize this in another file so that only one file change is required when updating this version? (I'm okay with enforcing the same version for all instances).


Solution

  • You can write a specific Helm setting for this value.

    # templates/deployment.yaml
    env:
      - name: PLUGIN_VERSION
        value: {{ .Values.pluginVersion }}
    {{ .Values.env | toYaml | indent 2 }}
    

    Now you can set that specific value in a common values file

    # values-common.yaml
    pluginVersion: 0.0.0
    

    and pass both the per-environment settings and the common settings when you install the chart

    helm install \
      -f values-common.yaml \
      -f values-dev.yaml \
      myapp1 .
    

    Other paths like helm install --set-string pluginVersion=0.0.1 will also work here, but writing a YAML (or JSON) file tends to be syntactically a little cleaner.