Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes persistent volume accessmode

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.

like image 302
wangzhe Avatar asked Jun 06 '16 04:06

wangzhe


People also ask

What are access modes in persistent volume?

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.

What are types of Kubernetes persistent volume access modes?

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.

What is ReadWriteOnce in Kubernetes?

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.

What are persistent volumes in Kubernetes?

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.


Video Answer


1 Answers

I think the upvoted answer is wrong. As per Kubernetes docs on Access Modes

The access modes are:

  • 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

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.

like image 93
0xMH Avatar answered Sep 28 '22 04:09

0xMH