<p>I have a pod that is defined by a deployment, and the yaml definition is stored in my codebase. There are time when I'd like to have a volume mount configured for the pod/container, so it would be great to have a script that could enable this. I know I can use <code>kubectl edit</code> to open up an editor and do this (then restart the pod), but it would be more applicable if our devs could simply do something like <code>./our_scripts/enable_mount.sh</code>.</p>

<p>One option would be to simply have a copy of the YAML definition and create/apply that while deleting the other, but it would be nicer to modify the existing one in place.</p>

<p>Is there a way to achieve this? Does <code>kubectl edit</code> have any flags that I'm missing to achieve this?</p>

s g
<p>Use <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/" rel="nofollow noreferrer">Declarative Management of Kubernetes Objects Using Kustomize</a>. You already have a <code>deployment.yaml</code> manifest in your codebase. Now, move that to <code>base/deployment.yaml</code> and also create a <code>overlays/with-mount/deployment-with-mount.yaml</code> that <em>overrides</em> with an mount when you want.</p>

<p>To deploy the base, you use</p>

<pre><code>kubectl apply -k base/deployment.yaml
</code></pre>

<p>and when you want to deploy and also override so you get a mount, you use</p>

<pre><code>kubectl apply -k overlays/with-mount/deployment-with-mount.yaml
</code></pre>
