<p>I am new to Helm and I want to create multiple deployments in k8s from a single deployment YAML file.
I've used a placeholder in the deployment.yaml like</p>
<pre><code>metadata:
  name: job-{{ .Values.app.ujn }}
...
replicas: {{ .Values.app.replicas }}
</code></pre>
<p>and my values.yaml looks like</p>
<pre><code>app:
  replicas: 10
  ujn: 1
---
app:
  replicas: 20
  ujn: 2
---
app:
  replicas: 30
  ujn: 3
</code></pre>
<p>The use case is something like that I want to create many deployment files with similar configuration but some params changed and I also don't want to make multiple values file for each deployment. Can I do something like that in the above example and create multiple files from a single values.yaml?</p>
<p>Also a follow up question, if I deploy this chart on the cluster and if I modify the number of deployments in next deploy, will helm delete the old ones or do those have to be deleted manually?</p>

Akshit Bansal
<p>The syntax you have puts multiple YAML <em>documents</em> into a single file.  It's unusual for tools to support this well (though <code>kubectl apply</code> and the output of Helm templates do support it); the most common case is that a tool will only read the first document.</p>
<p>Instead of having multiple documents, you can put a YAML list into the values file.</p>
<pre class="lang-yaml prettyprint-override"><code># values.yaml
apps:
  - name: '1'
    replicas: 10
  - name: '2'
    replicas: 20
  - name: '3'
    replicas: 30
</code></pre>
<p>Then in your template file, you can use a <code>range</code> loop to loop over this.  Here Helm <em>does</em> support multiple documents in a single output stream, so you need to make sure each template begins with the YAML start-of-document marker.  Also remember that the <code>range</code> loop rebinds <code>.</code> so you may need different syntax for the top-level Helm objects like <code>.Values</code> or <code>.Release</code>, or if you call a helper template.</p>
<pre class="lang-yaml prettyprint-override"><code>{{- range $app := .Values.apps -}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ $.Release.Name }}-job-{{ $app.name }}
  # labels: {{- include &quot;mychart.labels&quot; $ | nindent 4 }}
spec:
  replicas: {{ $app.replicas }}
  template: { ... }
{{ end }}
</code></pre>
