<p>I have a script which execute on container and i use following command to create my container and exit once execution complete, this is working as per our requirement.</p>
<pre><code>kubectl run -i tmp-pod --rm -n=mynamespace --image=placeholder --restart=Never --overrides=&quot;$(cat POD.json)&quot;
</code></pre>
<p>it creates the pod and execute my script and terminate the pod itself once completed.</p>
<p>But my above <code>kubectl</code> command runs by many sources  so if two source run same time then i get error <code>Error from server (AlreadyExists): pods &quot;POD_NAME&quot; already exists</code></p>
<p>Is there anyway i can make my pod name unique so parallels  run does not conflict with other pod?</p>
<p>here is my POD.json</p>
<pre><code>{
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;kind&quot;: &quot;Pod&quot;,
    &quot;metadata&quot;: {
        &quot;name&quot;: &quot;POD_NAME&quot;,
         
    },
    &quot;spec&quot;: {
        &quot;restartPolicy&quot;: &quot;Never&quot;,
        &quot;containers&quot;: [
            {
                &quot;name&quot;: &quot;POD_NAME&quot;,
                &quot;image&quot;: &quot;my_IMAGE:2&quot;,
                &quot;imagePullPolicy&quot;: &quot;Always&quot;,
                &quot;command&quot;: [
                    &quot;python&quot;,
                    &quot;/myscript.py&quot;,
                    &quot;INPUT_1&quot;,
                    &quot;INPUT_2&quot;
                ]
            }
        ]
    }
}
</code></pre>

<p>In your case, as everything is the same, I suggest you run your pod something like this. As far as I know, k8s does not give you a build in solution for this.</p>
<pre class="lang-sh prettyprint-override"><code>kubectl run -i tmp-pod$((1 + $RANDOM % 1000000)) --rm -n=mynamespace --image=placeholder --restart=Never --overrides=&quot;$(cat POD.json)&quot;
</code></pre>
<p>For documentation purpose, in case the POD.json has changing values: Using JQ, you can read the changing values in the POD.json like this</p>
<pre class="lang-sh prettyprint-override"><code>kubectl run -i tmp-pod$(cat POD.json | jq -r '.metadata.name') --rm -n=mynamespace --image=placeholder --restart=Never --overrides=&quot;$(cat POD.json)&quot;
</code></pre>
<p>In case the value you are reading is not valid as pod name, you could also simply generate a md5sum based on the POD.json and use a part of that like this. Using cut, to shorten it.</p>
<pre class="lang-sh prettyprint-override"><code>kubectl run -i tmp-pod$(md5sum POD.json | cut -c1-10) --rm -n=mynamespace --image=placeholder --restart=Never --overrides=&quot;$(cat POD.json)&quot;
</code></pre>
