2

Kubernetes newbie here, so my question might not make sense. Please bear with me.

So my question is, given I have setup Storage Class in my cluster, then I have a PVC (Which uses that Storage Class). If I use that PVC into my Deployment, and that Deployment have 5 replicas, will the Storage Class create 5 PV? one per Pod? Or only 1 PV shared by all Pods under that Deployment?

Edit: Also I have 3 Nodes in this cluster

Thanks in advance.

Jplus2
  • 2,216
  • 2
  • 28
  • 49

2 Answers2

2

The Persistent Volume Claim resource is specified separately from a deployment. It doesn't matter how many replicas the deployment has, kubernetes will only have the number of PVC resources that you define.

If you are looking for multiple stateful containers that create their own PVC's, use a StatefulSet instead. This includes a VolumeClaimTemplate definition.

If you want all deployment replicas to share a PVC, the storage class provider plugin will need to be either ReadOnlyMany or ReadWriteMany

Matt
  • 68,711
  • 7
  • 155
  • 158
  • So if my PVC access mode is ReadWriteOnce, the Storage Class will provision 5 PVs, 1 per pod? is that correct? – Jplus2 Apr 12 '20 at 01:29
  • In a StatefulSet with a VolumeClaimTemplate with 5 replicas you would get 5 PVC's, the mode doesn't matter. – Matt Apr 12 '20 at 02:52
1

To answer my question directly.

The Storage Class in this case will only provision one PV and is shared across all pods under the Deployment which uses that PVC.

The accessModes of the PVC does not dictate whether to create one PV for each pod. You can set the accessModes to either ReadWriteOnce/ReadOnlyMany/ReadWriteMany and it will always create 1 PV.

If you want that each Pod will have its own PV, you can not do that under a Deployment

You will need to use StatefulSet using volumeClaimTemplates.

It is Important that the StatefulSet uses volumeClaimTemplates or else, it will still act the same as the Deployment, that is the Storage Class will just provision one PV that is shared across all pods under that StatefulSet.

References:

Kubernetes Deployments vs StatefulSets

Is there a way to create a persistent volume per pod in a kubernetes deployment (or statefulset)?

Jplus2
  • 2,216
  • 2
  • 28
  • 49