<p>I have a running k8s deployment, with one container.</p>
<p>I want to deploy 10 more containers, with a few differences in the deployment manifest (i.e command launched, container name, ...).</p>
<p>Rather than create 10 more .yml files with the whole deployment, I would prefer use templating. What can I do to achieve this ?</p>
<pre><code>---
apiVersion: v1
kind: CronJob
metadata:
  name: myname
  labels:
    app.kubernetes.io/name: myname
spec:
  schedule: &quot;*/10 * * * *&quot;
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            app.kubernetes.io/name: myname
        spec:
          serviceAccountName: myname
          containers:
            - name: myname
              image: 'mynameimage'
              imagePullPolicy: IfNotPresent
              command: [&quot;/my/command/to/launch&quot;]
          restartPolicy: OnFailure
</code></pre>

Cowboy
<p>Using helm which is a templating engine for Kubernetes manifests you can create your own template by following me through.</p>
<blockquote>
<p>If you have never worked with <code>helm</code> you can check the <a href="https://helm.sh/docs/" rel="nofollow noreferrer">official docs</a></p>
<blockquote>
<p>In order for you to follow make sure you have helm already installed!</p>
</blockquote>
</blockquote>
<h3>- create a new chart:</h3>
<pre class="lang-sh prettyprint-override"><code>helm create cowboy-app
</code></pre>
<p>this will generate a new project for you.</p>
<h3>- <strong>DELETE EVERYTHING WITHING THE <code>templates</code> DIR</strong></h3>
<h3>- <strong>REMOVE ALL <code>values.yaml</code> content</strong></h3>
<h3>- create a new file <code>deployment.yaml</code> in <code>templates</code> directory and paste this:</h3>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.appName }}
  labels:
    chart: {{ .Values.appName }}
spec:
  selector:
    matchLabels:
      app: {{ .Values.appName }}
  replicas: 1
  template:
    metadata:
      labels:
        app: {{ .Values.appName }}
    spec:
      containers:
{{ toYaml .Values.images | indent 8 }}     
</code></pre>
<h3>- in <code>values.yaml</code> paste this:</h3>
<pre class="lang-yaml prettyprint-override"><code>appName: cowboy-app
images:
  - name: app-1
    image: image-1
  - name: app-2
    image: image-2
  - name: app-3
    image: image-3
  - name: app-4
    image: image-4
  - name: app-5
    image: image-5    
  - name: app-6
    image: image-6
  - name: app-7
    image: image-7
  - name: app-8
    image: image-8
  - name: app-9
    image: image-9
  - name: app-10
    image: image-10                                     
</code></pre>
<p>So if you are familiar with helm you can tell that <code>{{ toYaml .Values.images | indent 10 }}</code> in the <strong>deployment.yaml</strong> is referring to data specified in <strong>values.yaml</strong> as YAML and by running <code>helm install release-name /path/to/chart</code> will generate and deploy a manifest file which is <strong>deployment.yaml</strong> that looks like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: cowboy-app
  labels:
    chart: cowboy-app
spec:
  selector:
    matchLabels:
      app: cowboy-app
  replicas: 1
  template:
    metadata:
      labels:
        app: cowboy-app
    spec:
      containers:
        - image: image-1
          name: app-1
        - image: image-2
          name: app-2
        - image: image-3
          name: app-3
        - image: image-4
          name: app-4
        - image: image-5
          name: app-5
        - image: image-6
          name: app-6
        - image: image-7
          name: app-7
        - image: image-8
          name: app-8
        - image: image-9
          name: app-9
        - image: image-10
          name: app-10
</code></pre>
