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 mountOptios 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.2Is there any way I can achieve this using kubectl cli like we add annotations to ingress rules and pods?
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