<p>I would like to find the best practice of creating several pods with different env values.</p>
<p>Let's say that my system should ping several websites every pod will ping a different website, the only difference is the URL,
I would like to write one deployment file for all the different pods and one file with the list of URLs and that k8s will create a pod for each URL in the list.</p>
<p>Is it possible?</p>

Tomer
<p>Posting this community wiki answer to give more of a baseline approach with some potential solutions rather than a definitive one.</p>
<p>Feel free to edit and expand.</p>
<hr />
<p>Addressing the question from the title:</p>
<blockquote>
<p>Kubernetes creation of multiple deployment with one deployment file</p>
</blockquote>
<p>You can't create a single <code>Deployment</code> that each replica would be different from each other.  The <code>Deployment</code> creates sets of identical <code>Pods</code>:</p>
<blockquote>
<p>What is a Deployment?</p>
<p><strong><em>Deployments</em> represent a set of multiple, identical <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/pod" rel="nofollow noreferrer">Pods</a> with no unique identities.</strong> A Deployment runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive. In this way, Deployments help ensure that one or more instances of your application are available to serve user requests. Deployments are managed by the Kubernetes Deployment controller.</p>
<p>-- <em><a href="https://cloud.google.com/kubernetes-engine/docs/concepts/deployment#what_is_a_deployment" rel="nofollow noreferrer">Cloud.google.com: Kubernetes Engine: Docs: Concepts: Deployment: What is a Deployment</a></em></p>
</blockquote>
<p>Some of the ways that you could achieve the setup that you've described:</p>
<ul>
<li>As pointed by @David Maze:</li>
</ul>
<blockquote>
<p>Yes, it is possible, by putting multiple complete Deployment specs in the same file. For the example you give, though, do these need to be separate processes, or can you achieve the same thing with a single Deployment worker and a job queue (like RabbitMQ) that pushes out the URLs?</p>
</blockquote>
<ul>
<li><p>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)</p>
</li>
<li><p>Use the Kubernetes official documentation on work queue topics:</p>
<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>Example:</h3>
<p>As I said previously, you can use <code>Helm</code> to template the workload and spawn different <code>Jobs</code> that would be configured with a different command.</p>
<blockquote>
<p>Side notes!</p>
<ul>
<li>Please do not treat this example as a production ready.</li>
<li>This example does not acknowledge persistently storing the data after the <code>Job</code> is finished. You would need to examine available solutions and choose the one that fits your needs the most.</li>
</ul>
</blockquote>
<p>Assuming that basic Helm template is created and it's having modified files:</p>
<ul>
<li><code>values.yaml</code></li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>jobs:
  - name: job1
    command: ['&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(100)&quot;']
  - name: job2
    command: ['&quot;perl&quot;,  &quot;-Mbignum=bpi&quot;, &quot;-wle&quot;, &quot;print bpi(200)&quot;']
</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 }}
spec:
  template:
    spec:
      containers:
      - name: {{ $jobs.name }}
        image: perl
        command: {{ $jobs.command}} 
      restartPolicy: Never
  backoffLimit: 4
---
{{- end }}
</code></pre>
<p>By above example you will create 2 <code>Jobs</code> that will calculate pi to its 100 or 200 decimal number. You can modify this example to support the workload that you are intending to run.</p>
<ul>
<li><code>$ kubectl get pods</code></li>
</ul>
<pre><code>NAME         READY   STATUS      RESTARTS   AGE
job1-sgr86   0/1     Completed   0          3h36m
job2-4jxh5   0/1     Completed   0          3h36m
</code></pre>
<ul>
<li><code>$ echo &quot;one:&quot;; kubectl logs job1-sgr86; echo &quot;two:&quot;; kubectl logs job2-4jxh5</code></li>
</ul>
<pre><code>one:
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
two:
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303820
</code></pre>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://serverfault.com/questions/993167/in-a-helm-template-how-can-i-use-items-in-1-list-to-iterate-over-another-list">Serverfault.com: Questions: In a Helm template how can I use items in 1 list to iterate over another list</a></em></li>
</ul>
