luksa/kubernetes-in-action

Chapter 10 - PV & PVC

Opened this issue · 1 comments

I create 3 gcp persistent disks as described pv-a, b, c
then i create kubernetes persistent volume as well. Once I create stateful set, the pods are not binding to the created volumes and instead creating its own PV.

image

I checked GCP as well, all storage disks are in Same zone as master

luksa commented

These days, you usually don't need to create PersistentVolumes manually, as almost every cluster has dynamic provisioning enabled, and will create a PV automatically for every PVC you create. There is a sentence on page 291 that says:

If your cluster supports dynamic provisioning, you don’t
need to create any PersistentVolumes manually (you can skip the next section). If it
doesn’t, you’ll need to create them as explained in the next section.

Now, if you specifically want the statefulset pods to bind to the three PVs you created manually, you need to set statefulset.spec.volumeClaimTemplates.spec.storageClassName to an empty string, as explained on page 189 in the "Forcing a PersistentVolumeClaim to be bound to one of the pre-provisioned PersistentVolumes" section.