CodeBlanks Logo Icon CodeBlanks

Access modes

Learn ReadWriteOnce, ReadOnlyMany and ReadWriteMany.

Access modes

Access modes say how a disk can be mounted at the same time:

  • ReadWriteOnce (RWO): a single node reads and writes. Cloud block disks (EBS, PD) are like this.
  • ReadOnlyMany (ROX): many nodes only read.
  • ReadWriteMany (RWX): many nodes read and write; file systems like NFS, CephFS and EFS are needed.
  • ReadWriteOncePod (RWOP): a single pod reads and writes.
$ kubectl get pv -o custom-columns=AD:.metadata.name,MOD:.spec.accessModes
AD        MOD
nfs-pv    [ReadWriteMany]
pvc-9c1d  [ReadWriteOnce]

The RWO trap

Using an RWO PVC in a multi-replica Deployment is a common mistake: if the replicas land on different nodes, the second can't attach the disk. Solutions: a separate disk per replica (StatefulSet), RWX storage, or moving the data to object storage (S3):

Warning  FailedAttachVolume  Multi-Attach error for volume "pvc-9c1d…"
         Volume is already exclusively attached to one node and can't be attached to another

Practice A shared upload area

Write a PersistentVolumeClaim YAML: name yuklemeler; ReadWriteMany under accessModes; storageClassName: nfs; resources.requests.storage: 20Gi.

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: yuklemeler
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nfs
  resources:
    requests:
      storage: 20Gi

Expected output

persistentvolumeclaim/yuklemeler created
NAME         STATUS   CAPACITY   ACCESS MODES   STORAGECLASS
yuklemeler   Bound    20Gi       RWX            nfs

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which mode is needed for 3 web pods on different nodes to write to the same upload folder?

  • ReadOnlyMany
  • ReadWriteOncePod
  • ReadWriteMany Correct answer
  • ReadWriteOnce

Explanation: An RWO disk can't be attached to a second node; the pod stays Pending or ContainerCreating.

2 Request read-write from many nodes.

Question
spec:
  accessModes:
    - ____
Answer
spec:
  accessModes:
    - ReadWriteMany

Explanation: RWX requires a shared file system.

3 Match the modes.

Term Meaning
RWO One node writes
ROX Many nodes read
RWX Many nodes write
RWOP One pod writes

All lessons in Advanced