Home > Back-end >  how can i have an access mode to allow one pod at a time to write and then many pods can read only?
how can i have an access mode to allow one pod at a time to write and then many pods can read only?

Time:05-25

I tried to do this :

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: master-pvc
spec:
  accessModes:
    - ReadWriteOnce
    - ReadOnlyMany
  resources:
    requests:
      storage: 1Gi

The node that needs access should readonly via

volumeMounts:
              - name: mastervol
                mountPath: /data/master/
                readOnly: true

and for the master who needs to read and write so that the change takes effect

volumeMounts:
              - name: mastervol
                mountPath: /data/master/

Now my question is that valid to achieve what i want?

CodePudding user response:

It is not a node that requests a volumeMount, but a container inside a Pod (many Pods may run in same node).

A PVC is 1-1 bound to a PV using a single access mode (even it supports many) at a time (see also access modes). So, you cannot have a PVC operating at the same time as ReadWriteOnce (for some Pods) and ReadOnlyMany (for some other Pods).

If you want to support 1 writer and many readers, one solution is to let them use a ReadWriteOnce volume and ensure that all Pods run on the same node the volume is mounted (e.g by using node affinity constraints).

  • Related