It seems that Kubernetes supports 3 kinds of access mode for persistent volume: ReadWriteOnce
, ReadOnlyMany
, ReadWriteMany
. I'm really curious about the scheduler strategy for a pod which uses the ReadWriteOnce
mode volume. For example, I created an RC which have pod num=2, I guess the two pods will be scheduled into the same host because they use the volume that has ReadWriteOnce
mode? I really want to know the source code of this part.
PersistentVolume resources support the following access modes: ReadWriteOnce: The volume can be mounted as read-write by a single node. ReadOnlyMany: The volume can be mounted read-only by many nodes. ReadWriteMany: The volume can be mounted as read-write by many nodes.
22, Kubernetes offered three access modes for PVs and PVCs: ReadWriteOnce – the volume can be mounted as read-write by a single node. ReadOnlyMany – the volume can be mounted read-only by many nodes. ReadWriteMany – the volume can be mounted as read-write by many nodes.
ReadWriteOnce access mode still can allow multiple pods to access the volume when the pods are running on the same node. ReadOnlyMany. the volume can be mounted as read-only by many nodes. ReadWriteMany. the volume can be mounted as read-write by many nodes.
A persistent volume is a piece of storage in a cluster that an administrator has provisioned. It is a resource in the cluster, just as a node is a cluster resource. A persistent volume is a volume plug-in that has a lifecycle independent of any individual pod that uses the persistent volume.
I think the upvoted answer is wrong. As per Kubernetes docs on Access Modes
The access modes are:
So AccessModes as defined today, only describe node attach (not pod mount) semantics, and doesn't enforce anything.
So to prevent two pods mount the same PVC even if they are scheduled to be run on the same node you can use pod anti-affinity. It is not the same as not to mount one volume to 2 pods scheduled on the same node. But anti-affinity can be used to ask scheduler not to run 2 pods on the same node. Therefore it prevents mounting one volume into 2 pods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With