Change a PV's accessmode from ReadWriteOnce to ReadWriteMany or vice versa for a workload deployment
search cancel

Change a PV's accessmode from ReadWriteOnce to ReadWriteMany or vice versa for a workload deployment

book

Article ID: 370821

calendar_today

Updated On:

Products

VMware Tanzu Kubernetes Grid Integrated Edition VMware Tanzu Kubernetes Grid Integrated (TKGi) VMware Tanzu Kubernetes Grid Integrated Edition (Core) VMware Tanzu Kubernetes Grid Integrated Edition 1.x VMware Tanzu Kubernetes Grid Integrated EditionStarter Pack (Core)

Issue/Introduction

The aim of this article is to change a PV's accessmode from either:

 - ReadWriteOnce to ReadWriteMany

   OR

 - ReadWriteOnce to ReadWriteMany

Environment

TKGi - 1.18.3

Cause

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

Resolution

Note below:

PV - Persistent Volume
PVC - Persistent Volume Claim
RWO - ReadWriteOnce
RWX - ReadWriteMany

Steps:

  1. Backup existing yaml resources ie PV, PVC, Deployment
    kubectl get pvc <your-pvc> -n <your-pvc-namespace> -o yaml > <your-pvc-backup>.yaml
  2. Backup the existing PV you wish to change RWO to RWX for also (this could be done using Velero)

  3. Change spec.persistentVolumeReclaimPolicy to Retain - if not set already.
    kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
  4. Scale down deployment pods to zero for all pods that use the PV. In my test I had a single pod so deleted it.
    kubectl scale --replicas=0 -n <your-deployment-namespace> deployment <your-deployment-name>
  5. As per step 1 backup the associating PVC yaml before deleting the PVC.

  6. Delete the PVC to free up the PV ie status = Released.
    kubectl delete pvc <your-pvc> -n <your-pvc-namespace>
  7. Free PV status to become Available
    kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"claimRef":{"uid":""}}}'
  8. Change the PV access mode to RWX
    kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"accessModes":["ReadWriteMany"]}}'
  9. Recreate the PVC with RWX

    To do this edit your PVC backup yaml's spec.accessModes from below:
    ...

    spec:
      accessModes:
      - ReadWriteOnce

    ...
    to below:
    ...

    spec:
      accessModes:
        - ReadWriteMany

    ...
    -- or vice versa depending on which you are changing from/to.

  10. Scale up deployment pods to required number for all pods in the deployment to use the PV
    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.

  11. Restore the spec.persistentVolumeReclaimPolicy to original setting - which may originally have been Retain.
    kubectl patch pv <your-pv> -n <your-pv-namespace> -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'

 

Additional Information

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."