Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

helm chart - value file variables

I am using a helm chart (with sub-charts) to deploy my application. I am using a value file for setting values.

I am looking a way to set variables in my value file (or any other place) that will be valid for my value file.

I have some sections (services) in my value files that I need to use the same value in it so I am looking for a variable in my value file. Is there any way that I can use variables for my value file? Thx

like image 945
Demi Goldberg Avatar asked Apr 30 '26 22:04

Demi Goldberg


1 Answers

Helm on its own can't do this.

If you control all of the charts and subcharts, you can allow specific values to have embedded Go templating. Helm includes a tpl extension function that will let you render an arbitrary string as a template. So if you have values

global:
  commonKey: some value
otherKey: '{{ .Values.global.commonKey }}'

then you can render

- name: OTHER_KEY
  value: '{{ tpl .Values.otherKey . }}'

But, you have to use tpl every place you access the key value(s); if you don't control the subcharts you may not be able to do this.

Higher-level tools may also let you do this. I'm familiar in particular with Helmfile which lets you declare multiple Helm charts and their settings, but also lets you use almost-Helm templating in many places. So your helmfile.yaml could specify:

environments:
  default:
    # These values are available when rendering templates in this file
    values:
      - commonKey: some value
releases:
  - name: my-service
    namespace: my-service
    chart: ./charts/my-service
    values:
      # List items can be file names or YAML dictionaries.
      # If it's a dictionary, arbitrary nested values.yaml content.
      # If it's a *.yaml.gotmpl file name, templating is applied to the file.
      - otherKey: '{{ .Values.commonKey }}'
        yetAnotherKey: '{{ .Values.commonKey }}'
      - ./my-service.yaml.gotmpl

Helmsman is simpler, but can only set chart values from environment variables; but I believe you can reference the same environment variable in different setString: options. You could also do something similar with the Terraform Helm provider, using Terraform's native expression syntax, particularly if you're already familiar with Terraform.

like image 148
David Maze Avatar answered May 04 '26 04:05

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!