kubernetes helm: How to set env variable of child chart in parent chart

6/4/2019

We are using helm to deploy many charts, but for simplicity let's say it is two charts. A parent chart and a child chart:

helm/parent 
helm/child

The parent chart has a helm/parent/requirements.yaml file which specifies:

dependencies:
  - name: child
    repository: file://../child
    version: 0.1.0

The child chart requires a bunch of environment variables on startup for configuration, for example in helm/child/templates/deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    spec:
      containers:
        env:
        - name: A_URL
          value: http://localhost:8080

What's the best way to override the child's environment variable from the parent chart, so that I can run the parent using below command and set the A_URL env variable for this instance to e.g. https://www.mywebsite.com?

helm install parent --name parent-release --namespace sample-namespace

I tried adding the variable to the parent's helm/parent/values.yaml file, but to no avail

global:
  repository: my_repo
  tag: 1.0.0-SNAPSHOT
child:
  env:
    - name: A_URL
      value: https://www.mywebsite.com

Is the syntax of the parent's value.yaml correct? Is there a different approach?

-- Bernie Lenz
kubernetes
kubernetes-helm

2 Answers

6/4/2019

Unless the value is set up using the templating system, there is no way to directly modify it in Helm 2.

-- coderanger
Source: StackOverflow

6/4/2019

In the child chart you have to explicitly reference a value from the configuration. (Having made this change you probably need to run helm dependency update from the parent chart directory.)

# child/templates/deployment.yaml, in the pod spec
env:
- name: A_URL
  value: {{ .Values.aUrl | quote }}

You can give it a default value for the child chart.

# child/values.yaml
aUrl: "http://localhost:8080"

Then in the parent chart's values file, you can provide an override value for that.

# parent/values.yaml
child:
  aUrl: "http://elsewhere"

You can't use Helm to override or inject arbitrary YAML, except to the extent the templates allow for it.

-- David Maze
Source: StackOverflow