Can Multiple Pods Use the Same PVC in Kubernetes?
The short answer is IT DEPENDS.
Let’s say you have a PVC called myclaim
:
NAME STATUS VOLUME CAPACITY
myclaim Bound pvc-f13e3b19-a025-4939-82b8-7f0e8ac11dd5 15Gi
You can go ahead and create multiple pods whose spec
try to use this PVC, K8S will allow us to schedule all these pods without any validation error:
apiVersion: v1
kind: Pod
metadata:
name: ...
spec:
volumes:
- name: pvc-storage
persistentVolumeClaim:
claimName: myclaim
containers:
- name: nginx-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: pvc-storage
But whether multiple pods are able to mount the same volume that the myclaim
PVC points to (pvc-f13e3b19-a025-4939-82b8-7f0e8ac11dd5
in the example above) depends upon the access mode of the PV/PVC:
ReadWriteOnce
– the volume can be mounted as read-write by a single 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.ReadWriteOncePod
– the volume can be mounted as read-write by a single pod.
If a pod is scheduled but unable to mount the volume, it will never execute (Running
state).