<p>i have helm chart which need to define multiple same variables name like this</p>
<pre><code>      containers:
      - name: APP_NAME
        image: CONTAINER_IMAGE
        envFrom:
        - secretRef:
            name: secret1
        - secretRef:
            name: secret2
        - configMapRef:
            name: configmap1
        - secretRef:
            name: secret3
</code></pre>
<p>i added the nonproduction.yaml chart like this</p>
<pre><code>envFrom:
  secretRef:
    name1: secret1
  secretRef:
    name2: secret2
  configmapRef:
    name3: configmap1
  secretRef:
    name4: secret3
</code></pre>
<p>and define the deployment.yaml</p>
<pre><code>      containers:
      - name: {{ .Values.appName }}
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        envFrom:
        - secretRef:
            name: {{ .Values.envFrom.secretRef.name1 }}
        - secretRef:
            name: {{ .Values.envFrom.secretRef.name2 }}
        - configMapRef:
            name: {{ .Values.envFrom.configmapRef.name3 }}
        - secretRef:
            name: {{ .Values.envFrom.secretRef.name4 }}
</code></pre>
<p>but it went to duplicate key on the terminal, how can i use same name variable on helm chart without changing the name?</p>
<p>edit: add number so we dont get dizzy by the 'name'</p>

arsaphone
<p>YAML supports a set of basic data structures, like JSON (and in fact a valid JSON file will generally be valid YAML).  In YAML's terminology, there are <em>scalars</em> (strings, numbers, booleans), <em>sequences</em> (lists, arrays), and <em>mappings</em> (dictionaries).</p>
<p>In the <code>values.yaml</code> file you've shown, <code>envFrom:</code> is a mapping, but three of the keys are the same; you've said that the property <code>secretRef</code> has the mapping value <code>{name1: value1}</code>, and also that the property <code>secretRef</code> has the mapping value <code>{name2: value2}</code>, and that's where Helm gets confused.</p>
<p>You can change the <code>values.yaml</code> file to a YAML sequence instead by putting a hyphen <code>-</code> before each item:</p>
<pre class="lang-yaml prettyprint-override"><code>envFrom:
  - secretRef:
      name1: secret1
  - secretRef:
      name2: secret2
  - et: cetera
# ^ add &quot;-&quot; before each item
</code></pre>
<p>At this point you can use the approach in <a href="https://stackoverflow.com/a/69489391">@karthik's answer</a> to copy this structure as-is into the YAML output, since the sequence form matches what Kubernetes expects here.</p>
<pre class="lang-yaml prettyprint-override"><code>envFrom: {{- toYaml .Values.envFrom | nindent 12 }}
</code></pre>
<p>If you did need to iterate through individual values here, since it is now a sequence, you can't reference an individual item by name (and it's not easy in Helm to find an item in a sequence of mappings with some property) but only by index or via the <code>range</code> iteration keyword.</p>
