<p>I'm trying to do something simple, just create two pods within a job. I'm looking at the documentation here: <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/#single-job-starts-controller-pod" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/job/#single-job-starts-controller-pod</a></p>
<p>While the documentation discusses parallelization it doesn't give much in the way of examples. The only example with one pod is given as:</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: [&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(2000)&quot;]
      restartPolicy: Never
  backoffLimit: 4
</code></pre>
<p>To create two pods I attempted effectively this:</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi1
        image: perl
        command: [&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(2000)&quot;]
      restartPolicy: Never
    spec:
      containers:
      - name: pi2
        image: perl
        command: [&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(2000)&quot;]
      restartPolicy: Never
  backoffLimit: 4
</code></pre>
<p>But that didn't get me two pods, instead it appears that only the second container ran in one pod.</p>
<p>It's not clear to me how I get my job to launch multiple pods. My pods don't need to run on the same machine, but they each need a unique environment variable to be set so the pods know what part of the work to do. The work is divided in an embarrassingly parallel way and with a fixed number of pods (2 in this example).</p>

<p>You can not have two different pod template in the same job. From the docs <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/#parallel-jobs" rel="nofollow noreferrer">here</a></p>
<p><strong>Parallel Jobs with a work queue:</strong></p>
<ul>
<li><p>do not specify <code>.spec.completions</code>, default to <code>.spec.parallelism</code>.</p>
</li>
<li><p><strong>the Pods must coordinate amongst themselves or an external service to
determine what each should work on. For example, a Pod might fetch a
batch of up to N items from the work queue</strong>.</p>
</li>
<li><p>each Pod is independently capable of determining whether or not all
its peers are done, and thus that the entire Job is done. when any
Pod from the Job terminates with success, no new Pods are created.</p>
</li>
<li><p>once at least one Pod has terminated with success and all Pods are
terminated, then the Job is completed with success.</p>
</li>
<li><p>once any Pod has exited with success, no other Pod should still be
doing any work for this task or writing any output. They should all
be in the process of exiting.</p>
</li>
</ul>
<p>For a work queue Job, you must leave </p>
<pre><code>.spec.completions
</code></pre>
<p> unset, and set </p>
<pre><code>.spec.parallelism
</code></pre>
<p> to a non-negative integer.</p>
