<p>I have created common helm charts. In <em>values.yml</em> file, I have set of env variables that need to be set as part of deployment.yaml file.</p>

<p>Snippet of values file.</p>

<pre><code>env:
  name: ABC
  value: 123
  name: XYZ
  value: 567
  name:  PQRS
  value: 345

</code></pre>

<p>In deployment.yaml, when the values are referred, only the last name/value are set, other values are overwritten.  How to read/set all the names/values in the deployment file? </p>

Sunil Gajula
<p>I've gone through a few iterations of how to handle setting sensitive environment variables. Something like the following is the simplest solution I've come up with so far:</p>

<p>template:</p>

<pre><code>{{- if or $.Values.env $.Values.envSecrets }}
env:
  {{- range $key, $value := $.Values.env }}
  - name: {{ $key }}
    value: {{ $value | quote }}
  {{- end }}
  {{- range $key, $secret := $.Values.envSecrets }}
  - name: {{ $key }}
    valueFrom:
      secretKeyRef:
        name: {{ $secret }}
        key: {{ $key | quote }}
  {{- end }}
{{- end }}
</code></pre>

<p>values:</p>

<pre><code>env:
  ENV_VAR: value
envSecrets:
  SECRET_VAR: k8s-secret-name
</code></pre>

<p>Pros:</p>

<p>syntax is pretty straightforward</p>

<p>keys are easily mergeable. This came in useful when creating CronJobs with shared secrets. I was able to easily override "global" values using the following:</p>

<pre><code>  {{- range $key, $secret := merge (default dict .envSecrets) $.Values.globalEnvSecrets }}
</code></pre>

<p>Cons:</p>

<p>This only works for secret keys that exactly match the name of the environment variable, but it seems like that is the typical use case.</p>
