<p>I have a Deployment like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
spec:
  template:
    volumeMounts:
      - mountPath: /home
        name: john-webos-vol
        subPath: home
      - mountPath: /pkg
        name: john-vol
        readOnly: true
        subPath: school
</code></pre>
<p>I want to change the Deloyment with the <code>kubectl patch</code> command, so it has the following <code>volumeMounts</code> in the <code>PodTemplate</code> instead:</p>
<p><strong>target.yaml:</strong></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
spec:
  template:
    volumeMounts:
      - mountPath: /home
        name: john-webos-vol
        subPath: home
</code></pre>
<p>I used the below command, but it didn't work.</p>
<pre class="lang-sh prettyprint-override"><code>kubectl patch deployment sample --patch &quot;$(cat target.yaml)&quot;
</code></pre>
<p>Can anyone give me some advice?</p>

sun lim
<p>You can use JSON patch <a href="http://jsonpatch.com/" rel="nofollow noreferrer">http://jsonpatch.com/</a></p>
<h4>Remove specific volume mount</h4>
<pre><code>kubectl patch deployment &lt;NAME&gt; --type json -p='[{&quot;op&quot;: &quot;remove&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/volumeMounts/0&quot;}]'
</code></pre>
<h4>Replace volume mounts with what you need</h4>
<pre><code>kubectl patch deployment &lt;NAME&gt; --type json -p='[{&quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/volumeMounts&quot;, &quot;value&quot;: [{&quot;mountPath&quot;: &quot;/home&quot;, &quot;name&quot;: &quot;john-webos-vol&quot;, &quot;subPath&quot;: &quot;home&quot;}]}]'
</code></pre>
<p>Kubectl cheet sheet for more info: <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#patching-resources" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/kubectl/cheatsheet/#patching-resources</a></p>
