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"}}'