<p>I have a values.yaml that has the following:</p>

<pre><code>abc:
  env:
  - name: name01
    value: value01
  - name: name02
    value: value02
</code></pre>

<p>and I have another values file values-dev.yaml that I add when installing using -f and it has:</p>

<pre><code>abc:
  env:
  - name: name03
    value: value03
</code></pre>

<p>and using range I list them in my template. My hope was that the list would become like this after both files are applied:</p>

<pre><code>abc:
  env:
  - name: name01
    value: value01
  - name: name02
    value: value02
  - name: name03
    value: value03
</code></pre>

<p>but the values-dev.yaml values will override the one in the values.yaml and it becomes:</p>

<pre><code>abc:
  env:
  - name: name03
    value: value03
</code></pre>

<p>How can I achieve merging these 2 lists with the same field names from different values files?</p>

arash moeen
<p>Short answer is, you can not merge <code>lists</code>. </p>

<p>In your case <code>abc.env</code> is the <code>key</code> and the <code>value</code> is a list. Let me re-write your first values file in an equivalent notation and it will be more clear:</p>

<pre><code>abc:
  env: [{name: name01, value: value01}, {name: name02, value: value02}]
</code></pre>

<p>So Helm is doing what is expected, overriding the key <code>abc.env</code> with the last provided one.</p>

<p>Solution is re-structuring your values files, like this:</p>

<pre><code>abc:
  env:
    name01: value01
    name02: value02
</code></pre>

<p>This way, you can merge and override your values files as desired. This way, it's also much easy to override a single value with command line flag, for example:</p>

<pre><code>--set abc.env.name01=different
</code></pre>

<p>With some Helm magic, it's easy to pass those values as environment variables to your pods: </p>

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