Search code examples
kuberneteskubernetes-podpersistent-volume-claims

Can we connect multiple pods to the same PVC?


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?


Solution

  • 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.