Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

helm - programmatically override subchart values.yaml

I'm writing a helm chart that uses the stable/redis chart as a subchart.

I need to override the storage class name used for both microservices within my chart, and within the redis chart.

I'm using helm 2.12.3

I would like to be able to specify redis.master.persistence.storageClass in terms of a template, like so

storage:
  storageClasses:
    name: azurefile

redis:
  usePassword: false
  master:
    persistence:
      storageClass: {{ $.Values.storage.storageClasses.name }}

Except, as I understand, templates aren't supported within values.yaml

As this is a public chart, I'm not able to modify it to depend on a global value as described here in the documentation

I considered using {{ $.Values.redis.master.persistence.storageClass }} elsewhere in my chart rather than {{ $.Values.storage.storageClasses.name }}, but this would:

  • Not hide the complexity of the dependencies of my chart
  • Not scale if I was to add yet another subchart dependency

In my values.yaml file I have:

storage:
  storageClasses:
    name: azurefile

redis:
  master:
    persistence:
      storageClass: azurefile

I would like to specify a single value in values.yaml that can be overwritten at chart deploy time.

e.g. like this

helm install --set storage.storageClasses.name=foo mychart

rather than

helm install --set storage.storageClasses.name=foo --set redis.master.persistence.storageClass mychart
like image 805
Michael F. Avatar asked Mar 29 '19 21:03

Michael F.


People also ask

How do I override values YAML in Helm?

You can use a --set flag in your Helm commands to override the value of a setting in the YAML file. Specify the name of the setting and its new value after the --set flag in the Helm command. The --set flag in the above command overrides the value for the <service>. deployment.

What is Subchart in Helm?

A subchart is considered "stand-alone", which means a subchart can never explicitly depend on its parent chart. For that reason, a subchart cannot access the values of its parent. A parent chart can override values for subcharts. Helm has a concept of global values that can be accessed by all charts.

What is TPL function in Helm?

Using the 'tpl' Function The tpl function allows developers to evaluate strings as templates inside a template. This is useful to pass a template string as a value to a chart or render external configuration files.

Can a parent chart override values for subcharts in helm?

A parent chart can override values for subcharts. Helm has a concept of global values that can be accessed by all charts. What we will build? Here, we are going to create a Django Helm Chart.

How to override the values passed to the chart in YAML?

For an initial deployment, if you want to change any of the values, you can do so by directly editing the values.yaml file using a plain text editor. Apart from editing the YAML file directly, there are two methods you can use to override the values that are being passed into the chart from the values.yaml file. The two methods are as follows:

How do I access the values passed into the helm chart?

Override values passed into the Helm chart through the Values.yaml file. The values.yaml file is available for each service as part of the Helm chart. It is a source of content for the Values built-in object offered by Helm templates. The Values built-in object provides access to the values passed into a chart.

How to pass values from parent to subchart in YAML?

Note that all values passed from the parent to the subchart are nested below a YAML key by the same name as the subchart. --set syntax is the same concept, just prefix the key with the subchart name ( --set subchartname.subchartkey=myvalue.


1 Answers

As you correctly mentioned, helm value files are plain yaml files which cannot contain any templates. For your use case, you'd need to use a templating system for your values files also which basically means you are also generating your value files on the go. I'd suggest taking a look at helmfile. This lets you share values file across multiple charts and application environments.

like image 168
mukesh Avatar answered Oct 11 '22 13:10

mukesh