The aim of this article is to change a PV's accessmode from either:
- ReadWriteOnce to ReadWriteMany
OR
- ReadWriteOnce to ReadWriteMany
TKGi - 1.18.3
Application requirements change and you either require PV to be access by:
- Single Pod or Node
- Multiple Pods or Nodes
- High Availability requirement
- Data Consistency
- Cost Management
Note below:
PV - Persistent Volume
PVC - Persistent Volume Claim
RWO - ReadWriteOnce
RWX - ReadWriteMany
Steps:
kubectl get pvc <your-pvc> -n <your-pvc-namespace> -o yaml > <your-pvc-backup>.yaml
kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
kubectl scale --replicas=0 -n <your-deployment-namespace> deployment <your-deployment-name>
kubectl delete pvc <your-pvc> -n <your-pvc-namespace>
kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"claimRef":{"uid":""}}}'
kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"accessModes":["ReadWriteMany"]}}'
...to below:
spec:
accessModes:
- ReadWriteOnce
...
...-- or vice versa depending on which you are changing from/to.
spec:
accessModes:
- ReadWriteMany
...
kubectl scale --replicas=1 -n <your-deployment-namespace> deployment <your-deployment-name>
Now all your workloads should commence to using your PV in RWO/RWX access mode.
All containers should then be checked to see if they were able to attach the PV(s) as required.
kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'
NOTE: For customers that are trying to change accessmode from ReadWriteOnce to ReadWriteMany or vice versa in a CNS environment, please note that it is not supported for vSphere CSI.
"The steps described in the KB is not supported by vSphere CSI. After a PVC is provisioned and bound, vSphere CSI does not support converting access mode from ReadWriteOnce to ReadWriteMany or vice versa. This is because RWO is for block volumes and RWX is for file volumes. They are very different underneath. Simply changing volume access mode in PV cannot change the volume that is already provisioned underneath."