<p>I'm trying to create a number of pods from a yaml loop in helm. if I run with <code>--debug --dry-run</code> the output matches my expectations, but when I actually deploy to to a cluster, only the last iteration of the loop is present.</p>

<p>some yaml for you: </p>

<pre><code>{{ if .Values.componentTests }}
{{- range .Values.componentTests }}
apiVersion: v1
kind: Pod
metadata:
  name: {{ . }}
  labels:
    app: {{ . }}
    chart: {{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "_" }}
    release: {{ $.Release.Name }}
    heritage: {{ $.Release.Service }}
spec:
{{ toYaml $.Values.global.podSpec | indent 2 }}
  restartPolicy: Never
  containers:
  - name: {{ . }}
    ports:
      - containerPort: 3000
    image: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/{{ . }}:latest
    imagePullPolicy: Always
    command: ["sleep"]
    args: ["100d"]
    resources:
      requests:
        memory: 2000Mi
        cpu: 500m
{{- end }}
{{ end }}
</code></pre>

<p>when I run  <code>helm upgrade --install --set componentTests="{a,b,c}" --debug --dry-run</code></p>

<p>I get the following output: </p>

<pre><code># Source: &lt;path-to-file&gt;.yaml
apiVersion: v1
kind: Pod
metadata:
  name: a
  labels:
    app: a
    chart: integrationtests-0.0.1
    release: funny-ferret
    heritage: Tiller
spec: 
  restartPolicy: Never
  containers:
  - name: content-tests
    ports:
      - containerPort: 3000
    image: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/a:latest
    imagePullPolicy: Always
    command: ["sleep"]
    args: ["100d"]
    resources:
      requests:
        memory: 2000Mi
        cpu: 500m
apiVersion: v1
kind: Pod
metadata:
  name: b
  labels:
    app: b
    chart: integrationtests-0.0.1
    release: funny-ferret
    heritage: Tiller
spec:  
  restartPolicy: Never
  containers:
  - name: b
    ports:
      - containerPort: 3000
    image: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/b:latest
    imagePullPolicy: Always
    command: ["sleep"]
    args: ["100d"]
    resources:
      requests:
        memory: 2000Mi
        cpu: 500m
apiVersion: v1
kind: Pod
metadata:
  name: c
  labels:
    app: users-tests
    chart: integrationtests-0.0.1
    release: funny-ferret
    heritage: Tiller
spec:
  restartPolicy: Never
  containers:
  - name: c
    ports:
      - containerPort: 3000
    image: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/c:latest
    imagePullPolicy: Always
    command: ["sleep"]
    args: ["100d"]
    resources:
      requests:
        memory: 2000Mi
        cpu: 500m
---
</code></pre>

<p>(some parts have been edited/removed due to sensitivity/irrelevance)</p>

<p>which looks to me like I it does what I want it to, namely create a pod for <code>a</code> another for <code>b</code> and a third for <code>c</code>.</p>

<p>however, when actually installing this into a cluster, I always only end up with the pod corresponding to the last element in the list. (in this case, <code>c</code>) it's almost as if they overwrite each other, but given that they have different names I don't think they should? even running with <code>--debug</code> but not <code>--dry-run</code> the output tells me I should have 3 pods, but using <code>kubectl get pods</code> I can see only one.</p>

<p>How can I iteratively create pods from a list using Helm?</p>

<p>found it! </p>

<p>so apparently, helm uses <code>---</code> as a separator between specifications of pods/services/whatHaveYou.</p>

<p>specifying the same fields multiple times in a single chart is valid, it will use the last specified value for for any given field. To avoid overwriting values and instead have multiple pods created, simply add the separator at the end of the loop:</p>

<pre><code>{{ if .Values.componentTests }}
{{- range .Values.componentTests }}
apiVersion: v1
kind: Pod
metadata:
  name: {{ . }}
  labels:
    app: {{ . }}
    chart: {{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "_" }}
    release: {{ $.Release.Name }}
    heritage: {{ $.Release.Service }}
spec:
{{ toYaml $.Values.global.podSpec | indent 2 }}
  restartPolicy: Never
  containers:
  - name: {{ . }}
    ports:
      - containerPort: 3000
    image: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/{{ . }}:latest
    imagePullPolicy: Always
    command: ["sleep"]
    args: ["100d"]
    resources:
      requests:
        memory: 2000Mi
        cpu: 500m
---
{{- end }}
{{ end }}
</code></pre>
