As per this official document, Kubernetes Persistent Volumes support three types of access modes.
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.
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:
ReadWriteMany
is an option given the volume plugin for your K8s cluster, use ReadWriteMany
.ReadWriteMany
simply isn't an available option for you, use ReadWriteOnce
.ReadOnlyMany
is an option given the volume plugin for your K8s cluster, use ReadOnlyMany
.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.