简体   繁体   中英

access kubernetes storage from multiple pods with different modes - one pod ReadWrite, other pods ReadOnly

I have a pod that needs to save data persistently to a place outside the pod. I think a persistentVolume is a good idea for that. The pod called writerPod needs ReadWrite-access to that volume.

Multiple other Pods (I'm calling them readingPods) need to read the files that writerPod saved.

Is it possible to have two persistentVolumeClaims (PVC) (that differ only in the accessMode ReadWriteOnce and ReadOnlyMany) that both bind the same PersistentVolume?

PVC can have more than one accessMode configured (both ReadOnlyMany and ReadWriteOnce):

  accessModes:
  - ReadWriteOnce
  - ReadOnlyMany

However, as the names imply, you can mount the disk to many pods in ReadOnlyMany (AKA ROX ) but only one pod at a time can use that disk in ReadWriteOnce mode (AKA RWO ).

If your readingPods should be up only after your writerPod has written its data - you can use the same PVC, just make sure your mounting the PVC with the readOnly flag set to true, for example:

volumes:
- name: test-volume
  persistentVolumeClaim:
    claimName: my-pvc
    readOnly: true

If you're using a Cloud provider that supports the ReadWriteMany access mode (Unfortunately, Google is not one of them right now) it will of-course suit you in all scenarios. Check the official documentation to check the supported modes on each platform.

The Document-1 says: ReadWriteMany: The volume can be mounted as read-write by many nodes. PersistentVolumes that are backed by Compute Engine persistent disks don't support this access mode.

The Document-2 says: If you attach a persistent disk to multiple instances, all of those instances must attach the persistent disk in read-only mode. It is not possible to attach the persistent disk to multiple instances in read-write mode. If you need to share dynamic storage space between multiple instances, you can use one of the following options:

Connect your instances to Cloud Storage Connect your instances to Filestore Create a network file server on Compute Engine

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