<p>I have 2 different values.yaml files per stage and production environment such as values.dev.yaml > values.prod.yaml and using with Helm 3. I would like to learn the best practices how to pass environment variables per environments.For instance we need to set different parameters to NODE_ENV variable.</p>

<p>-Should I specify the variable as hard coded as below and pass the environment variables when running <code>helm upgrade/install</code> command with <code>--set</code> flag?</p>

<p>-What is the correct way to use go template to do this. Can we specify something {{ .Values.node_env.value}} and then pass this env value in values yaml and use only -f values.yaml flag?</p>

<pre><code>      containers:
            - name: {{ .Chart.Name }}
              securityContext:
                {{- toYaml .Values.securityContext | nindent 12 }}
              image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              ports:
                - name: http
                  containerPort: 8080
                  protocol: TCP
              resources:
                {{- toYaml .Values.resources | nindent 12 }}
              env: 
              - name: "NODE_ENV"
                value: "stage"
              - name: "NODE_ENV"
                value: "production"
</code></pre>

semural
<p>If you have one value file per environment (it is not clear to me this is your case.) like values.prod.yaml (for prod) and values.dev.yaml (for dev), then your templeate can look like this.</p>

<p>This will cause the template to look for <code>extraEnv:</code> in your values{dev/prod}.yaml and iterate over all key/values from that section.</p>

<pre><code>  env:
    {{- range $key, $value := .Values.extraEnv }}
    - name: {{ $key }}
      value: {{ $value | quote }}
    {{- end }}
</code></pre>

<p>In your <em>values.dev.yaml</em> files you add all your <code>KEY: values</code> that are specific for this environment. Note you can have multiple key values here, all of them will be loaded. In this case we have NODE_ENV, ANOTHER_KEY, YET_ANOTHER_KEY - all of them will be loaded.</p>

<pre><code>extraEnv:
  NODE_ENV: stage
  ANOTHER_KEY: value
  YET_ANOTHER_KEY: value
</code></pre>

<p>same in your <em>values.prod.yaml</em> multiple <code>KEY: value</code> pairs can be specified and all of them will be loaded.</p>

<pre><code>extraEnv:
  NODE_ENV: production
  ANOTHER_KEY: value
</code></pre>
