Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 259
geets Avatar asked Jul 16 '20 19:07

geets


1 Answers

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.

like image 131
hilsenrat Avatar answered Oct 19 '22 12:10

hilsenrat