<p>I would like to know if there is a way to launch a pod from a yaml but with a custom name.</p>
<p>The objective of all this is to be able to add to the pod name something like a user id and then be able to delete it when the user requires it, having this way an unequivocal way to find the pod.</p>
<p>It would be something like:</p>
<pre><code>kubectl apply -f ./foo.yaml -name custom-name
</code></pre>
<p>Thanks in advance!</p>

AdCerros
<p>You can't do that with <code>kubectl</code>, but you can:</p>
<ul>
<li><p>Perform the substitution with something like <code>sed</code> and pipe the result to <code>kubectl apply</code>:</p>
<pre><code>sed 's/PODNAME/custom-name/' foo.yaml |
  kubectl apply -f-
</code></pre>
<p>(This assumes that you have <code>name: PODNAME</code> in the original manifest.)</p>
</li>
<li><p>Use a YAML processing tool to make the change. For example, using <a href="https://kislyuk.github.io/yq/" rel="nofollow noreferrer"><code>yq</code></a> (note that there are multiple commands with that name; hence the link).</p>
<pre><code>yq '.metadata.name = &quot;custom-name&quot;' foo.yaml |
  kubectl apply -f-
</code></pre>
<p>This has the advantage that you don't need a specific sentinel name like <code>PODNAME</code> in the source file.</p>
</li>
<li><p>Create a Helm template and deploy the manifest(s) with <code>helm</code>, in which case you could set the value on the command line.</p>
<pre><code>helm install &lt;your/repository&gt; --set-string podname=custom-name
</code></pre>
</li>
<li><p>Use some other templating tool, such as Ansible's <a href="https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html" rel="nofollow noreferrer"><code>k8s</code> module</a>.</p>
</li>
</ul>
