kuberneteskubernetes-pvc

In kubernetes why does PVC claim to be waiting for consumer before binding but appears to be bound?


I have a PVC which is used by numerous pods and should be bound to a PV using ram disk

When I try to describe the PVC I get the following message:

waiting for first consumer to be created before binding

I don't understand that, because it sure looks bound to me. If I do a describe on the PV I'm pretty sure the PVC is bound to it says there is a claim for default/PVC_name

If I log into the shell of the containers that are using that PVC I can ls the mounted directory, see files are being saved and read etc.

By all indication I can tell that PVC sure looks bound, so why does the describe message say otherwise?


Solution

  • Possible workaround 1 : Persistent volumes not auto provisioned on k8s 1.24

    Before k8s 1.24, the default StorageClass was standard, which uses volumeBindingMode Immediate. However, since k8s 1.24, the default StorageClass is standard-rwo, which uses volumeBindingMode WaitForFirstConsumer.

    This behavior is intended and actually preferred. Please create a workload that consumes the PVC, then a PV will be created.

    update your StorageClass to immediate:

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: local-storage
    provisioner: kubernetes.io/no-provisioner
    volumeBindingMode: Immediate  # <-- bind as soon as PVC is created
    

    WaitForFirstConsumer will only bind when a Pod uses your PVC.

    Please check Persistent volumes and dynamic provisioning for more information.

    Possible workaround 2 : Check you might have created your PV on the master node. By default the master node is marked unschedulable by ordinary pods using so called taint. To be able to run some service on master node you have two options:

    1. Add toleration to some service to allow it to run on master node:
    2. You can remove taint from the master node, so any pod can run on it. You should know that this is dangerous because it can make your cluster very unstable.

    Please go through the similar SO for more information.