13

I mean is there a one to one or many to one relationship between pod and PVC? Can I connect two or more pods to the same PVC(persistent volume claims) without deleting or disconnecting the earlier created pods?

Aniket
  • 153
  • 1
  • 2
  • 8

2 Answers2

14

Can I connect two or more pods to the same PVC(persistent volume claims) without deleting or disconnecting the earlier created pods?

Yes, this works. But in practice this is a bit more complicated.

Persistent Volumes can be created with different access modes. Your storage system may limit what access modes you can use. E.g. the access mode ReadWriteMany is only available in some storage systems. The access mode ReadWriteOnce is most commonly available.

For multiple Pods accessing a Persistent Volume mounted with access mode ReadWriteOnce, they must be scheduled to the same node to concurrently access the volume.

For multiple Pods accessing a Persistent Volume mounted with access mode ReadWriteMany or ReadOnlyMany, the Pods can be scheduled to different nodes. But in a "cloud provider" environment, where you use multiple Availability Zones in a Region, your Persistent Volume is typically only accessible within one Availability Zone, so you must make sure that your Pods are scheduled to the same Availability Zone. Cloud providers typically offer Regional volumes as well, but they are more expensive and you need to use a specific storage class for this.

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • But, the accessModes setting is something you use on the PVC, right? As far as I understand, there can be multiple PVC(s) connected to a single PV, because of the accessModes field. But, I don't know if multiple pods can use the same PVC or not? – Aniket May 01 '21 at 15:12
  • The accessMode on the PVC is what the app request, it will get a PV with at least support for that accessMode. Yes, there can be multiple Pods using the same PVC. – Jonas May 01 '21 at 15:32
  • Does it say implicitly that the same PVC can not be shared with Pods? "Resource quantities can be added and subtracted: for example, a node has a fixed quantity of each resource type that can be allocated to pods/containers; once such an allocation has been made, the allocated resources cannot be made available to other pods/containers without over-committing the resources. " https://github.com/kubernetes/design-proposals-archive/blob/main/scheduling/resources.md – NEERAJ SWARNKAR Mar 23 '23 at 13:18
  • @NEERAJSWARNKAR pods on the same node can share the same PVC. – Jonas Mar 23 '23 at 15:14
8

Yea, It's one of the common use case. If the PVC has a accessMode of ReadWriteMany then multiple pods can mount the volumes at the same time.

Here 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

for further details access-modes

Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
  • But as far as I understand, the access mode is something that the PVC and PV share. That is, there can be multiple PVC(s) with respect to a PV. But, I don't if its the same with pods and PVC(s) – Aniket May 01 '21 at 15:08
  • 1
    so roughly speaking, first part is the PVC and Storage Class, both of these resources help to create a persistent volume on storage system, now second part is if this volume has capability with access mode of RWM such as a NFS , it can be mounted by multiple Nodes then to Pods at the same time but if the Volume such a Block storage (iscsi voumes) which has RWO,then it can only be mounted with single node. – Suresh Vishnoi May 01 '21 at 23:03
  • 1
    these limitation comes from storage system such as file system and block storage, you can read further about it. – Suresh Vishnoi May 02 '21 at 00:35