Helm: How to overrride the values of subcharts using parent chart?

5/24/2020

We have an umbrella structure like that:

 -app1
  templates/...
  values.yaml
 -app2
  templates/...
  values.yaml
  values/dev.yaml

I want to be able to deploy the entire umbrella with different values file according to different environment (dev, prod), of the sub chart

  1. app2 to be installed with values.yaml only
  2. app2 to be installed with values.yaml and the values/dev.yaml

Is that possible?

-- Mickey Hovel
kubernetes
kubernetes-helm

1 Answer

5/24/2020

Nope that's not possible, but there is a workaround to achieve the functionality, a change in the directory structure will be required. Before reading any further check out the similar question here How to set environment related values.yaml in Helm subcharts?

The above scenario can be achieved with the following directory structure:

test-umbrella - Chart.yaml
      - values.yaml
      - requirements.yaml
      - charts - test-dev - Chart.yaml
                           - values.yaml
               - test-prod - Chart.yaml
                           - values.yaml
      - templates - deployment.yaml
                  - _helpers.tpl
                  - secret.yaml

The chart dependencies should be defined like this: requirements.yaml

dependencies:
  - name: tesy-dev
    repository: "file://charts/test-dev"
    version: ">= 0.0.1"
    tags:
      - dev-values
    import-values:
      - data

  - name: test-prod
    repository: "file://charts/test-prd"
    version: ">= 0.0.1"
    tags:
      - prd-values
    import-values:
      - data

Parent chart's values.yaml file should contain values like this:

values.yaml

# Default values

tags:
  dev-values: false
  prd-values: false

And then finally you should install it with the following flag --set tags.dev-values=true

In umbrella chart you must be having a parent values.yaml file. If you define your keys there, then the values of subcharts will be overwritten by it.

So you can have a values-dev.yaml outside the subchart to overwrite the internal subchart values.

Moreover you should have all the values that can be changed accordingly due to environment in the parent charts values.yaml so that they can be overwritten easily.

Please check best practices and flow of execution https://helm.sh/docs/chart_template_guide/subcharts_and_globals/

-- redzack
Source: StackOverflow