<p>What you are describing is best achieved by either using two jobs or let task 1 also be an init Container as they run in sequence.
Alternatively you could use Argo Workflows. 
<a href="https://github.com/argoproj/argo" rel="nofollow noreferrer">https://github.com/argoproj/argo</a></p>

CC BY-SA 4.0
2020-04-09T19:16:42.523Z
2020-04-09T19:16:42.523Z
therianthropie
<p>In this SO article I understand that I can run a sequence of <code>initContainers</code> before running the containers defined in <code>spec.template.spec.containers</code>. </p>

<p><a href="https://stackoverflow.com/questions/40713573/how-to-run-containers-sequentially-as-a-kubernetes-job">https://stackoverflow.com/questions/40713573/how-to-run-containers-sequentially-as-a-kubernetes-job</a></p>

<p>I have two independent containers, each of which requires a sequence of <code>initContainers</code> to run in series prior to the container running.</p>

<p>Is it possible to run both sequences of <code>initContainers</code> at the same time? Something like this:</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: my-test-job
spec:
  backoffLimit: 0
  template:
    spec:
      initContainers:
      - name: init1
        image: busybox
        command: ["echo", "Init 1 Ran!"]
      containers:
      - name: task1
        image: busybox
        imagePullPolicy: Always
        command: ["echo", "Task 1 Ran!"]
      restartPolicy: Never

    spec:
      initContainers:
      - name: init2
        image: busybox
        command: ["echo", "Init 2 Ran!"]
      containers:
      - name: task2
        image: busybox
        imagePullPolicy: Always
        command: ["echo", "Task 2 Ran!"]
      restartPolicy: Never
</code></pre>

<p>It's not valid to duplicate <code>spec</code> as I did in that example of what I'm attempting to achieve. But it demonstrates the sequence of events I want. Initially <code>init1</code> and <code>init2</code> kick off, and once each finishes, <code>task1</code> and <code>task2</code> start following their respective init containers.</p>

<kubernetes><yaml>
Running two containers in a kubernetes job each with their own initContainers
David Parks
# Running two containers in a kubernetes job each with their own initContainers

(Asked by: username_0 on 2020-04-07)

In this SO article I understand that I can run a sequence of initContainers before running the containers defined in spec.template.spec.containers. 
https://stackoverflow.com/questions/40713573/how-to-run-containers-sequentially-as-a-kubernetes-job
I have two independent containers, each of which requires a sequence of initContainers to run in series prior to the container running.
Is it possible to run both sequences of initContainers at the same time? Something like this:
apiVersion: batch/v1
kind: Job
metadata:
  name: my-test-job
spec:
  backoffLimit: 0
  template:
    spec:
      initContainers:
      - name: init1
        image: busybox
        command: ["echo", "Init 1 Ran!"]
      containers:
      - name: task1
        image: busybox
        imagePullPolicy: Always
        command: ["echo", "Task 1 Ran!"]
      restartPolicy: Never

    spec:
      initContainers:
      - name: init2
        image: busybox
        command: ["echo", "Init 2 Ran!"]
      containers:
      - name: task2
        image: busybox
        imagePullPolicy: Always
        command: ["echo", "Task 2 Ran!"]
      restartPolicy: Never

It's not valid to duplicate spec as I did in that example of what I'm attempting to achieve. But it demonstrates the sequence of events I want. Initially init1 and init2 kick off, and once each finishes, task1 and task2 start following their respective init containers.

**Tags:** kubernetes, yaml


---

## 1 answers

### Answer by username_1 on 2020-04-09. Score: 2 | Accepted answer

What you are describing is best achieved by either using two jobs or let task 1 also be an init Container as they run in sequence.
Alternatively you could use Argo Workflows.
<https://github.com/argoproj/argo>


---

