<p>I have a Kubernetes <code>Job</code>, <code>job.yaml</code> :</p>
<pre><code>---
apiVersion: v1
kind: Namespace
metadata:
  name: my-namespace
---
apiVersion: batch/v1
kind: Job
metadata:
  name: my-job
  namespace: my-namespace
spec:
  template:
    spec:
      containers:
      - name: my-container
        image: gcr.io/project-id/my-image:latest
        command: [&quot;sh&quot;, &quot;run-vpn-script.sh&quot;, &quot;/to/download/this&quot;] # need to run this multiple times
        securityContext:
          privileged: true
          allowPrivilegeEscalation: true
      restartPolicy: Never
</code></pre>
<p>I need to run <code>command</code> for different parameters. I have like 30 parameters to run. I'm not sure what is the best solution here. I'm thinking to create container in a loop to run all parameters. How can I do this? I want to run the <code>commands</code> or containers all simultaneously.</p>

<p>Some of the ways that you could do it outside of the solutions proposed in other answers are following:</p>
<ul>
<li>With a templating tool like <code>Helm</code> where you would template the exact specification of your workload and then iterate over it with different values (see the example)</li>
<li>Use the Kubernetes official documentation on work queue topics:
<ul>
<li><a href="https://kubernetes.io/docs/tasks/job/indexed-parallel-processing-static/" rel="nofollow noreferrer">Indexed Job for Parallel Processing with Static Work Assignment</a> - alpha</li>
<li><a href="https://kubernetes.io/docs/tasks/job/parallel-processing-expansion/" rel="nofollow noreferrer">Parallel Processing using Expansions</a></li>
</ul>
</li>
</ul>
<hr />
<h3><code>Helm</code> example:</h3>
<p><code>Helm</code> in short is a templating tool that will allow you to template your manifests (<code>YAML</code> files). By that you could have multiple instances of <code>Jobs</code> with different name and a different command.</p>
<p>Assuming that you've installed <code>Helm</code> by following guide:</p>
<ul>
<li><em><a href="https://helm.sh/docs/intro/install/" rel="nofollow noreferrer">Helm.sh: Docs: Intro: Install</a></em></li>
</ul>
<p>You can create an example Chart that you will modify to run your <code>Jobs</code>:</p>
<ul>
<li><code>helm create chart-name</code></li>
</ul>
<p>You will need to delete everything that is in the <code>chart-name/templates/</code> and clear the <code>chart-name/values.yaml</code> file.</p>
<p>After that you can create your <code>values.yaml</code> file which you will iterate upon:</p>
<pre class="lang-yaml prettyprint-override"><code>jobs:
  - name: job1
    command: ['&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(3)&quot;']
    image: perl
  - name: job2
    command: ['&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(20)&quot;']
    image: perl
</code></pre>
<ul>
<li><code>templates/job.yaml</code></li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>{{- range $jobs := .Values.jobs }}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ $jobs.name }}
  namespace: default # &lt;-- FOR EXAMPLE PURPOSES ONLY!
spec:
  template:
    spec:
      containers:
      - name: my-container
        image: {{ $jobs.image }}
        command: {{ $jobs.command }}
        securityContext:
          privileged: true
          allowPrivilegeEscalation: true
      restartPolicy: Never
---
{{- end }}
</code></pre>
<p>If you have above files created you can run following command on what will be applied to the cluster beforehand:</p>
<ul>
<li><code>$ helm template .</code> (inside the <code>chart-name</code> folder)</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>---
# Source: chart-name/templates/job.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: job1
  namespace: default
spec:
  template:
    spec:
      containers:
      - name: my-container
        image: perl
        command: [&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(3)&quot;]
        securityContext:
          privileged: true
          allowPrivilegeEscalation: true
      restartPolicy: Never
---
# Source: chart-name/templates/job.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: job2
  namespace: default
spec:
  template:
    spec:
      containers:
      - name: my-container
        image: perl
        command: [&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(20)&quot;]
        securityContext:
          privileged: true
          allowPrivilegeEscalation: true
      restartPolicy: Never
</code></pre>
<blockquote>
<p>A side note #1!</p>
<p>This example will create <code>X</code> amount of <code>Jobs</code> where each one will be separate from the other. Please refer to the documentation on data persistency if the files that are downloaded are needed to be stored persistently (example: <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/persistent-volumes" rel="nofollow noreferrer">GKE</a>).</p>
</blockquote>
<blockquote>
<p>A side note #2!</p>
<p>You can also add your <code>namespace</code> definition in the templates (<code>templates/namespace.yaml</code>) so it will be created before running your <code>Jobs</code>.</p>
</blockquote>
<p>You can also run above Chart by:</p>
<ul>
<li><code>$ helm install chart-name .</code> (inside the <code>chart-name</code> folder)</li>
</ul>
<p>After that you should be seeing 2 <code>Jobs</code> that are completed:</p>
<ul>
<li><code>$ kubectl get pods</code></li>
</ul>
<pre class="lang-sh prettyprint-override"><code>NAME         READY   STATUS      RESTARTS   AGE
job1-2dcw5   0/1     Completed   0          82s
job2-9cv9k   0/1     Completed   0          82s
</code></pre>
<p>And the output that they've created:</p>
<ul>
<li><code>$ echo &quot;one:&quot;; kubectl logs job1-2dcw5; echo &quot;two:&quot;; kubectl logs job2-9cv9k</code></li>
</ul>
<pre class="lang-sh prettyprint-override"><code>one:
3.14
two:
3.1415926535897932385
</code></pre>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://stackoverflow.com/questions/68159868/kubernetes-creation-of-multiple-deployment-with-one-deployment-file/68251390#68251390">Stackoverflow.com: Questions: Kubernetes creation of multiple deployment with one deployment file</a></em></li>
</ul>
