Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Persistent Volume Access Modes: ReadWriteOnce vs ReadOnlyMany vs ReadWriteMany

As per this official document, Kubernetes Persistent Volumes support three types of access modes.

  1. ReadOnlyMany
  2. ReadWriteOnce
  3. ReadWriteMany

The given definitions of them in the document is very high-level. It would be great if someone can explain them in little more detail along with some examples of different use cases where we should use one vs other.

like image 700
ACloudRoamer Avatar asked Sep 05 '19 04:09

ACloudRoamer


People also ask

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 access mode ReadWriteOnce?

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 is the difference between persistent volume and persistent volume claim in Kubernetes?

PVCs are requests for those resources and also act as claim checks to the resource. So a persistent volume (PV) is the "physical" volume on the host machine that stores your persistent data. A persistent volume claim (PVC) is a request for the platform to create a PV for you, and you attach PVs to your pods via a PVC.

Can two pods use same PVC?

Once a PV is bound to a PVC, that PV is essentially tied to the PVC's project and cannot be bound to by another PVC. There is a one-to-one mapping of PVs and PVCs. However, multiple pods in the same project can use the same PVC.


3 Answers

You should use ReadWriteX when you plan to have Pods that will need to write to the volume, and not only read data from the volume.

You should use XMany when you want the ability for Pods to access the given volume while those workloads are running on different nodes in the Kubernetes cluster. These Pods may be multiple replicas belonging to a Deployment, or may be completely different Pods. There are many cases where it's desirable to have Pods running on different nodes, for instance if you have multiple Pod replicas for a single Deployment, then having them run on different nodes can help ensure some amount of continued availability even if one of the nodes fails or is being updated.

If you don't use XMany, but you do have multiple Pods that need access to the given volume, that will force Kubernetes to schedule all those Pods to run on whatever node the volume gets mounted to first, which could overload that node if there are too many such pods, and can impact the availability of Deployments whose Pods need access to that volume as explained in the previous paragraph.

So putting all that together:

  • If you need to write to the volume, and you may have multiple Pods needing to write to the volume where you'd prefer the flexibility of those Pods being scheduled to different nodes, and ReadWriteMany is an option given the volume plugin for your K8s cluster, use ReadWriteMany.
  • If you need to write to the volume but either you don't have the requirement that multiple pods should be able to write to it, or ReadWriteMany simply isn't an available option for you, use ReadWriteOnce.
  • If you only need to read from the volume, and you may have multiple Pods needing to read from the volume where you'd prefer the flexibility of those Pods being scheduled to different nodes, and ReadOnlyMany is an option given the volume plugin for your K8s cluster, use ReadOnlyMany.
  • If you only need to read from the volume but either you don't have the requirement that multiple pods should be able to read from it, or ReadOnlyMany simply isn't an available option for you, use ReadWriteOnce. In this case, you want the volume to be read-only but the limitations of your volume plugin have forced you to choose ReadWriteOnce (there's no ReadOnlyOnce option). As a good practice, consider the containers.volumeMounts.readOnly setting to true in your Pod specs for volume mounts corresponding to volumes that are intended to be read-only.
like image 56
Amit Kumar Gupta Avatar answered Oct 24 '22 10:10

Amit Kumar Gupta


  1. ReadOnlyMany – the volume can be mounted read-only by many nodes

By this method, multiple pods running on multiple nodes can use a single volume and read data.

If a pod mounts a volume with ReadOnlyMany access mode, other pod can mount it and perform only read operation. Right now GCP is not supporting this method.

This means a volume can be mounted on one or many nodes of your Kubernetes cluster and you can only perform read operation.

You have one pod is running on node and you are reading stored file from volume. While on same volume you can not perform writes.

As it's ReadOnlyMany, if your pod is scheduled to another node, then also volume and data will be available to perform read operation.

  1. ReadWriteMany – the volume can be mounted as read-write by many nodes

By this method, multiple pods running on multiple nodes can use a single volume and read/write data.

If a pod mounts a volume with ReadWriteMany access mode, other pod can also mount it.

This means the volume can be mounted on one or many node of your Kubernetes cluster and you can perform both, read and write operation.

You have one pod running on a node and you are reading & writing the stored file from the volume.

As it's ReadWriteMany if your pod schedule to another node then also the volume and data will be available there to perform read/write operation.

for this, you can use NFS (MinIO, GlusterFS) or EFS filesystem also.

  1. ReadWriteOnce – the volume can be mounted as read-write by a single node

If a pod mounts a volume with ReadWriteOnce access mode, no other pod can mount it. In GCE (Google Compute Engine) the only allowed modes are ReadWriteOnce and ReadOnlyMany. So either one pod mounts the volume ReadWrite, or one or more pods mount the volume ReadOnlyMany.

This means the volume can be mounted on only one node of your kubernetes cluster and you can only perform read operation.

You have one pod running on node and you are reading stored file from volume. While on same volume you cannot perform writes.

As it's ReadWriteOnce if your pod is scheduled to another node then may mossible volume will be attached to the node and you can not get access of data there.

like image 7
Harsh Manvar Avatar answered Oct 24 '22 10:10

Harsh Manvar


In Kubernetes you provision storage either statically(using a storage class) or dynamically (Persistent Volume). Once the storage is available to bound and claimed, you need to configure it in what way your Pods or Nodes are connecting to the storage (a persistent volume). That could be configured in below four modes.

  1. ReadOnlyMany (ROX)

In this mode multiple pods running on different Nodes could connect to the storage and carry out read operation.

  1. ReadWriteMany (RWX)

In this mode multiple pods running on different Nodes could connect to the storage and carry out read and write operation.

  1. ReadWriteOnce (RWO)

In this mode multiple pods running in only one Node could connect to the storage and carry out read and write operation.

  1. ReadWriteOncePod (RWOP)

In this mode the volume can be mounted as read-write by a single Pod. Use ReadWriteOncePod access mode if you want to ensure that only one pod across whole cluster can read that PVC or write to it. This is only supported for CSI volumes and Kubernetes version 1.22+.

Folow the documentation to get more insight.

like image 5
Aditya Bhuyan Avatar answered Oct 24 '22 09:10

Aditya Bhuyan