I am trying to understand the Access Modes of Kubernetes PersistentVolumes
.
As per the Kubernetes docs, 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
Volume Plugin HostPath
supports ReadWriteOnce
I have a K8s cluster of 1 controlplane and 1 worker1 node
I deployed two Pods one to each node, pv, pvc in the same namespace
as per the below config. Both the pods running on different nodes are able to Read-Write to the local path /tmp/test
.
As per my understanding, this should not happen. Only one node should be able to ReadWrite and another node should only be able to Read.
Can someone explain what is happening here, if possible please provide me with examples/blogs to see the differences between RWO, RWX, ROX
? Most of the blogs, just talk about the PV, PVC and access modes in brief.
apiVersion: v1
kind: Pod
metadata:
name: pod2
spec:
nodeName: controlplane
containers:
- image: nginx
name: pod2
volumeMounts:
- name: vol
mountPath: /usr/share/nginx/html
volumes:
- name: vol
persistentVolumeClaim:
claimName: pvc
---
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
nodeName: worker1
containers:
- image: nginx
name: pod1
volumeMounts:
- name: vol
mountPath: /usr/share/nginx/html
volumes:
- name: vol
persistentVolumeClaim:
claimName: pvc
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/test
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi