Search code examples
kubernetespersistent-volumespersistent-volume-claims

Add MountOptions to Kubernetes ingress rule from cli


I have a PV/PVC in my kubernetes cluster.

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

I want to externally add mountOptions to all PVs like below.

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

Is there any way I can achieve this using kubectl cli like we add annotations to ingress rules and pods?


Solution

  • You can use kubectl patch command to add mountOptions to existing PV in the cluster:

    kubectl patch pv pv0003 --patch '{"spec": {"mountOptions": ["hard","nfsvers=4.1"]}}'
    

    If you want to add mountOptions to every PV in the cluster you can use simple bash for loop and kubectl patch command:

    for pv in $(kubectl get pv --no-headers -o custom-columns=":metadata.name"); do kubectl patch pv $pv --patch '{"spec": {"mountOptions": ["hard","nfsvers=4.1"]}}'; done