<p>I'd like to create a copy of a k8s pod on the fly,
and patch it with some custom configurations.</p>
<p>Unfortunately,
I don't really know where to start from...</p>
<pre><code>  my-service
    - kustomization.yaml
    - deployment.yaml
</code></pre>
<p>And then</p>
<pre><code>kubectl apply -k ./path/to/my-service --override `{ &quot;image&quot;: &quot;foo-1&quot;, &quot;name&quot;: &quot;foo-1&quot; }`
</code></pre>
<p>the override I am talking about should supply dynamic informations to the deployment,
such as info I only have at build time, etc.</p>
<hr />
<h3>A.C</h3>
<ul>
<li>[ ] The original <code>my-service</code> pod should not be changed, the <em>on-the-fly-deployment</em> should create a new, ephemeral, pod.</li>
<li>[ ] The new ephemeral pod should have all the informations from the <code>original</code></li>
</ul>

Hitmands
<p>You could use a simple base and overlay:</p>
<pre><code>my-service/
  base/
    kustomization.yml
    deployment.yml
  overlays/
    ephemeral/
      kustomization.yml
</code></pre>
<p><code>my-service/base/kustomization.yml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>resources:
  - deployment.yml
</code></pre>
<p>If you don't need a specific name for the ephemeral deployment:</p>
<p><code>my-service/overlays/ephemeral/kustomization.yml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>resources:
  - ../../base

nameSuffix: '-ephemeral'

images:
  - name: myImage
    newName: foo-1

replicas:
  - name: my-deployment
    count: 1
</code></pre>
<p>If you need a specific name you will have to patch the name in <code>my-service/overlays/ephemeral/kustomization.yml</code>.
You can then run:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -k my-service/base
kubectl apply -k my-service/overlays/ephemeral
</code></pre>
<p>To be clear, this will create two deployments: the original and one deployment of a single pod. Not one deployment and one lone pod.</p>
