简体   繁体   中英

Can I change Access mode of PVC from RWO(Standard storageclass) to RWX(NFS storageclass) without losing data?

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?

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.

You cannot change your StorageClass to a different one and expect the data to not be lost .You won't be even able to change most of the parameters in already created StorageClasses and PVC's.Changing the StorageClass for a PVC that stores your data will not transfer the data to a new location.

As said by @Manmohan Mittal, You need to create a new PVC for NFS storage class and copy the backup of existing pv data to the mounted volume.

However you can edit the PersistentVolume accessmodes to RWX that will automatically update PVC accessmodes without losing any data in the NFS Storage class.

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.

In Kube.netes 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              standard             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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM