<p>So, I have a pod definition file and I was wondering if there was a way to use the kubectl apply command to create multiple instances of the pod from the same definition file. I know this can be done with a deployment but wondering if there was a way to quickly spin up multiple pods using the apply command?</p>

<blockquote>
<p>I know this can be done with a deployment but wondering if there was a
way to quickly spin up multiple pods using the apply command?</p>
</blockquote>
<p>Yes, this is possible but not with the simple <code>kubectl apply</code> command as it doesn't have such options/capabilities and cannot be used to create multiple instances of a pod from a single yaml definition file.</p>
<p>If you just need to create <strong>n number</strong> of independent pods, not managed by any <code>replicaset</code>, <code>deployment</code>, <code>statefulset</code> etc., you can use for this purpose a simple bash one-liner.</p>
<p>Suppose we want to quickly spin up 10 independent pods based on the following yaml template, named <code>pod-template.yaml</code>:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: {{pod-name}}
spec:
  containers:
    - name: web
      image: nginx
      ports:
        - name: web
          containerPort: 80
          protocol: TCP
</code></pre>
<p>We can do it with the following script:</p>
<pre><code>for i in {1..10}; do sed &quot;s/{{pod-name}}/pod-$i/g&quot; pod-template.yaml | kubectl apply -f - ; done
</code></pre>
<p>It will create 10 pods named <code>pod-1</code>, <code>pod-2</code> ... <code>pod-10</code>:</p>
<pre><code>$ for i in {1..10}; do sed &quot;s/{{pod-name}}/pod-$i/g&quot; pod-template.yaml | kubectl apply -f - ; done
pod/pod-1 created
pod/pod-2 created
pod/pod-3 created
pod/pod-4 created
pod/pod-5 created
pod/pod-6 created
pod/pod-7 created
pod/pod-8 created
pod/pod-9 created
pod/pod-10 created
</code></pre>
<p>And just in case you want to delete them now and don't want to do it one by one ;)</p>
<pre><code>for i in {1..10};do kubectl delete pod pod-$i; done
</code></pre>
