<p>I'm bit new to kubernetes, I know we can create multiple deployments using same template. I have already gone through <a href="https://stackoverflow.com/questions/65024441/using-single-helm-chart-for-deployment-of-multiple-services">this</a>. But my requirement is slight different. I have 30 deployment files wherein only two parameters that's deployment <code>name</code> and <code>python script1.py</code> keeps on updating for all deployments. Below are sample deployment files</p>
<p><code>deployment1.yaml</code></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: deploy1    &lt;-- Will be updated every time for all deployments
  name: deploy1     &lt;-- Will be updated every time for all deployments
spec:
  replicas: 3
  selector:
    matchLabels:
      app: deploy1
  strategy:
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: deploy1
    spec:
      containers:
      - name: web
        image: nginx
        command: [&quot;/bin/sh&quot;]
        args:
          - -c
          - &gt;-
              python script1.py     &lt;-- Will be updated every time for all deployments
</code></pre>
<p><code>deployment2.yaml</code></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: deploy2    &lt;-- Will be updated every time for all deployments
  name: deploy2     &lt;-- Will be updated every time for all deployments
spec:
  replicas: 3
  selector:
    matchLabels:
      app: deploy2
  strategy:
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: deploy2
    spec:
      containers:
      - name: web
        image: nginx
        command: [&quot;/bin/sh&quot;]
        args:
          - -c
          - &gt;-
              python script2.py     &lt;-- Will be updated every time for all deployments
</code></pre>
<p>I want to know how can I convert this into single template so that multiple deployments can be deployed into the cluster. Eventually I want to integrate this into cloud build as a part of my CI/CD.</p>
<p>Any help would be appreciated here.</p>
<p><strong>Update 1 :</strong></p>
<p>@Moritz Schmitz v. Hülst I have updated my code to include below files in my helm chart.</p>
<p>here is my <code>values.yaml</code></p>
<pre><code>deployments:
  - image: nginx
  - name: deploy1
    script: script1.py
  - name: deploy2
    script: script2.py
</code></pre>
<p>template/deployment.yaml</p>
<p>{{- range .Values.deployments }}</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ .name }}
  name: {{ .name }}
spec:
  replicas: 3
  selector:
    matchLabels:
      app: {{ .name }}
  strategy:
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: {{ .name }}
    spec:
      containers:
      - name: web
        image: {{ .image }}
        ports:
        - containerPort: 80
{{- end }}
</code></pre>
<p>template/service.yaml</p>
<pre><code>{{- range .Values.deployments }}
apiVersion: v1
kind: Service
metadata:
  name: {{ .name }}
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: {{ .name }}
{{- end }}
</code></pre>
<p>I get below error while running <code>helm install demo-nginx demo-hello/</code>,</p>
<blockquote>
<p>Error: INSTALLATION FAILED: unable to build kubernetes objects from
release manifest: error validating &quot;&quot;: error validating data: [unknown
object type &quot;nil&quot; in Deployment.metadata.labels.app, unknown object
type &quot;nil&quot; in Deployment.spec.selector.matchLabels.app, unknown object
type &quot;nil&quot; in Deployment.spec.template.metadata.labels.app]</p>
</blockquote>

Rahul
<p>deployment.yaml:</p>
<pre><code>{{- range .Values.deployments }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ .name }}
  name: {{ .name }}
spec:
  replicas: 3
  selector:
    matchLabels:
      app: {{ .name }}
  strategy:
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: {{ .name }}
    spec:
      containers:
      - name: web
        image: nginx
        command: [&quot;/bin/sh&quot;]
        args:
          - -c
          - &gt;-
              python {{ .script }}
{{- end }}
</code></pre>
<p>values.yaml:</p>
<pre><code>deployments:
  - name: deploy1
    script: script1.py
  - name: deploy2
    script: script2.py
</code></pre>
