Sub topic 5
Access modes
This chapter assumes you can write a PersistentVolume and a PersistentVolumeClaim and know how a claim binds to a volume. It covers what an access mode promises and how to choose one.
What an access mode describes
An access mode states how many nodes, or Pods, may use a volume at the same time, and whether they may write. Both PersistentVolumes and PersistentVolumeClaims carry an accessModes list.
| Mode | Short name | Meaning |
|---|---|---|
| ReadWriteOnce | RWO | Read-write by Pods on a single node |
| ReadOnlyMany | ROX | Read-only by Pods on many nodes |
| ReadWriteMany | RWX | Read-write by Pods on many nodes |
| ReadWriteOncePod | RWOP | Read-write by a single Pod in the whole cluster |
RWO limits the number of nodes, not Pods. Several Pods on the same node can mount an RWO volume together. If you need exactly one Pod, use RWOP. It works only with CSI drivers.
A volume may list several modes, but it is mounted with only one mode at a time. A volume that supports both ROX and RWO cannot be mounted read-write on one node and read-only on another.
Modes are a capability, not a lock
The storage backend decides what a volume can do. The access mode is a label that Kubernetes uses to match claims to volumes and to schedule Pods. It does not make a volume safe for shared writes. An RWX volume still needs an application that handles concurrent writers.
During binding, every mode in the claim must also appear in the volume. A claim asking for ReadWriteMany will not bind to a volume that offers only ReadWriteOnce.
Choosing a mode
Which modes you can pick depends on the backend. Block storage such as AWS EBS supports RWO and RWOP. Shared file systems such as NFS or Amazon EFS support RWX.
Example
This claim asks for exclusive use by a single Pod. The StorageClass must use a CSI driver that supports RWOP.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: exclusive-pvc
spec:
accessModes:
- ReadWriteOncePod
storageClassName: fast
resources:
requests:
storage: 5GiCheck the modes with kubectl get pv and kubectl get pvc. The ACCESS MODES column shows the short names.
kubectl get pvc exclusive-pvcCommon errors
- Claim stays Pending. The requested mode is not offered by any matching volume or by the StorageClass provisioner. Run
kubectl describe pvcand read the events. - Multi-Attach error. A Deployment with an RWO volume is rolled out, and the new Pod is scheduled on a different node while the old Pod still holds the volume. Use the
Recreatestrategy, a single replica, or RWX storage. - Second Pod stuck Pending with RWOP. Only one Pod may use the claim. This is the intended behavior, not a fault.
- Assuming RWX is available. Many block-storage classes cannot provide it. Check what your driver supports.
Exercise
Two Pods on the same node both mount a PVC with ReadWriteOnce. Why does this work, and what mode would you use to forbid it?
Show answer
ReadWriteOnce limits access to one node, not one Pod, so both Pods on that node can mount the volume read-write. ReadWriteOncePod allows only one Pod in the whole cluster, so it forbids this.
Exercise
A PVC requests ReadWriteMany, and the only available PV lists ReadWriteOnce. Will they bind?
Show answer
No. Every mode the claim requests must be offered by the volume, so the claim stays Pending.