<p>I have a template that is basically an utility container for running kubectl inside a pod.</p>

<p>What I want to do, is to be able to have multiple deployments of that same template, with different names, as in "utilitypod-randomID".</p>

<p>Is there a way to do that, via kubectl and some shell scripting, or something similar?</p>

<p>The current template looks like this:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: utilitypod
  namespace: blah-dev
labels:
  purpose: utility-pod
spec:
  containers:
  - name: utilitypod
  image: blahblah/utilitypod:latest
  command: [ "/bin/bash", "-c", "--" ]
  args: [ "while true; do sleep 28800; done;" ]
  env: 
  - name: KUBERNETES_SERVICE_HOST
    value: "api.dev.blah.internal"
  - name: KUBERNETES_SERVICE_PORT
    value: "443"
</code></pre>

<p>You can replace <code>name</code> with <code>generateName</code>, which adds a random suffix. Your template will look like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  generateName: utilitypod-
  namespace: blah-dev
  labels:
    purpose: utility-pod
spec:
  containers:
    - name: utilitypod
      image: blahblah/utilitypod:latest
      command: [ &quot;/bin/bash&quot;, &quot;-c&quot;, &quot;--&quot; ]
      args: [ &quot;while true; do sleep 28800; done;&quot; ]
      env:
        - name: KUBERNETES_SERVICE_HOST
          value: &quot;api.dev.blah.internal&quot;
        - name: KUBERNETES_SERVICE_PORT
          value: &quot;443&quot;
</code></pre>
<p>Mind you, this will only work with <code>kubectl create -f template.yaml</code>, not <code>apply</code>, as <code>apply</code> looks for a resource by its name and tries to compare their definitions, but this template doesn't contain a specific name.</p>
