Home > Software engineering >  Can I change Access mode of PVC from RWO(Standard storageclass) to RWX(NFS storageclass) without los
Can I change Access mode of PVC from RWO(Standard storageclass) to RWX(NFS storageclass) without los

Time:04-13

I know we can edit the pvc and change to RWX but there is a cache in this, I'm trying to do in GKE, so for my pvc with RWO the storage class is standard, but if edit to RWX i need to change the storage class also to NFS.

Is it possible to achieve this without losing data inside PVC ?

CodePudding user response:

Your existing pvc is using the standard storage class which doesn’t allow RWX . So it’s not possible. It means even if you change it in PVC config it’s not going to work.

Workaround to the above is take the backup of existing pv data. Create a new pvc with RWX mode for NFS pv and mount that to the application. Copy the backup data to the mounted volume.

CodePudding user response:

A PersistentVolume can be mounted on a host in any way supported by the resource provider. Providers will have different capabilities and each PV's access modes are set to the specific modes supported by that particular volume. For example, NFS can support multiple read/write clients, but a specific NFS PV might be exported on the server as read-only. Each PV gets its own set of access modes describing that specific PV's capabilities.

There are three types of access modes supported in kubernetes.

RWO - ReadWriteOnce

ROX - ReadOnlyMany

RWX - ReadWriteMany

In Kubernetes Persistent Volume, it's mentioned that NFS supports all types of Access. RWO, RXX and RWX. AccessModes in PersistenceVolumeClaim (PVC) is an immutable field and cannot be changed once applied.

You can change the bounded PersistentVolume(PV) accessModes which will automatically update PVC AccessModes.

kubectl get PV

NAME       CAPACITY     ACCESS MODES     RECLAIM POLICY          STATUS   CLAIM        STORAGECLASS       REASON         AGE 

my_pv         50Gi          RWX              Delete                  Available              local-storage             2d22h

kubectl edit pv my_pv and change to desired access mode.

accessModes:
     - ReadWriteMany

This will change the PVC AccessModes and the output is

kubectl get pvc

NAME        STATUS       VOLUME         CAPACITY     ACCESS MODES  STORAGE CLASS      AGE 

 my_pvc     Bound     pvc-xxxx-xxxx-xxx     1Gi        ROX       standard            2s 

Here, PVC is created with the ROX Accessmode in standard storageclass.

  • Related