<p>I have a PV/PVC in my kubernetes cluster.</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  nfs:
    path: /tmp
    server: 172.17.0.2
</code></pre>
<p>I want to externally add <code>mountOptions</code> to all PVs like below.</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /tmp
    server: 172.17.0.2
</code></pre>
<p>Is there any way I can achieve this using <code>kubectl</code> cli like we add annotations to ingress rules and pods?</p>

<p>You can use <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/" rel="nofollow noreferrer"><code>kubectl patch</code> command</a> to add <code>mountOptions</code> to existing PV in the cluster:</p>
<pre><code>kubectl patch pv pv0003 --patch '{&quot;spec&quot;: {&quot;mountOptions&quot;: [&quot;hard&quot;,&quot;nfsvers=4.1&quot;]}}'
</code></pre>
<p>If you want to add <code>mountOptions</code> to every PV  in the cluster you can use simple bash <code>for</code> loop and <code>kubectl patch</code> command:</p>
<pre><code>for pv in $(kubectl get pv --no-headers -o custom-columns=&quot;:metadata.name&quot;); do kubectl patch pv $pv --patch '{&quot;spec&quot;: {&quot;mountOptions&quot;: [&quot;hard&quot;,&quot;nfsvers=4.1&quot;]}}'; done
</code></pre>
