Sub topic 14
Binding modes and topology: WaitForFirstConsumer
This chapter assumes you know how a StorageClass triggers dynamic provisioning and how a claim binds to a volume. Here you will see when that binding happens, and why the timing matters.
Two binding modes
The volumeBindingMode field of a StorageClass controls when a PersistentVolumeClaim (PVC) binds and when the volume is provisioned.
| Mode | Binding and provisioning happen | Typical use |
|---|---|---|
| `Immediate` (default) | As soon as the PVC is created | Storage reachable from every node |
| `WaitForFirstConsumer` | When a Pod that uses the PVC is scheduled | Zonal or node-local storage |
The topology problem
Many volumes exist in only one place. An EBS volume lives in a single availability zone, and a local disk lives on a single node. A Pod can attach such a volume only if it runs where the volume is.
With Immediate, the provisioner has to pick a location before any Pod exists, so it guesses. If the scheduler later places the Pod in a different zone, the Pod cannot attach the volume and stays Pending. The volume is already bound, so Kubernetes cannot move it.
With WaitForFirstConsumer, the PVC stays Pending until a Pod references it. The scheduler then picks a node using the Pod's CPU requests, affinity rules, and taints, along with the volume constraints. The provisioner creates the volume in that node's zone, and the claim binds.
Configuring it
This is the StorageClass from the earlier chapters. The last two fields are the ones that matter here.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast
provisioner: ebs.csi.aws.com
parameters:
type: gp3
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: trueAfter you create a PVC with this class, kubectl get pvc shows Pending. This is normal. Describe the claim to confirm:
kubectl describe pvc demo-pvcThe events section reports WaitForFirstConsumer, with a message like "waiting for first consumer to be created before binding". The claim binds only after you create a Pod that mounts it.
Common errors
- Static PVs and
WaitForFirstConsumer. A class that uses this mode delays binding to pre-created PVs as well. The scheduler considers the PV's node affinity when it places the Pod. - Pod stays Pending after the claim binds. The Pod's node selector or affinity may conflict with the volume's zone. Compare the PV's
nodeAffinitywith the Pod's constraints. - Pods that bypass the scheduler. A Pod with
spec.nodeNameset skips the scheduler. The claim then does not get a node selection, so avoidnodeNamewith this mode. - Changing the mode on an existing class.
volumeBindingModeis immutable. Create a new StorageClass instead.
Exercise
A PVC uses a StorageClass with volumeBindingMode: WaitForFirstConsumer. It has been Pending for ten minutes, and no Pod references it. Is something broken, and what do you do?
Show answer
Nothing is broken. The claim waits for a Pod that uses it. Create the Pod, and the scheduler will pick a node, the provisioner will create a volume in that node's zone, and the claim will bind. Use kubectl describe pvc to confirm the WaitForFirstConsumer event.