Sub topic 7
How a Claim Binds to a Volume
This chapter assumes you know Pods, namespaces, and kubectl apply. It also assumes you have seen a PersistentVolume (PV) and a PersistentVolumeClaim (PVC) manifest. Binding is the step that connects the two.
What binding means
Binding is a one-to-one link between a PVC and a PV. The control plane's PV controller watches for unbound claims and looks for a matching volume. When it finds one, it records the link on both objects. The PV's spec.claimRef names the claim, and the PVC's spec.volumeName names the volume. After that, no other claim can use that PV, even if the PV is larger than the request.
Matching rules
For a static PV, the controller checks these fields. All of them must pass.
| Field | Rule |
|---|---|
| `storageClassName` | Must be identical on the claim and the volume. |
| `accessModes` | The volume must offer every mode the claim requests. |
| `volumeMode` | Must match (`Filesystem` or `Block`). |
| `resources.requests.storage` | The volume's capacity must be at least the request. |
| `selector` (optional) | The volume's labels must match the claim's label selector. |
The controller picks the smallest PV that satisfies the claim. A 1Gi claim can therefore bind to a 100Gi volume if nothing smaller matches, and the whole 100Gi is then reserved for that claim.
Binding the example volume and claim
Apply the demo-pv and demo-pvc manifests from earlier in the tutorial. Both use storageClassName: manual, ReadWriteOnce, and 1Gi, so they match.
kubectl get pv
kubectl get pvc
kubectl describe pvc demo-pvckubectl get pv should show demo-pv with STATUS Bound and a CLAIM of default/demo-pvc. kubectl get pvc should show demo-pvc as Bound with VOLUME demo-pv.
A claim with no match stays Pending. The controller keeps retrying, so creating a matching PV later still binds the claim. kubectl describe pvc shows the reason in the Events section.
Reserving a volume for one claim
Matching can pick an unintended PV. To reserve a PV for a specific claim, set claimRef on the PV. Setting volumeName on the claim does the same from the other direction.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: demo-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: manual
volumeName: demo-pv
resources:
requests:
storage: 1GiThe other checks, such as class, modes, and size, still apply.
Binding with dynamic provisioning
If the claim names a StorageClass that has a provisioner, the controller does not search for an existing PV first. It asks the provisioner to create a new volume, then binds the claim to it. When the class sets volumeBindingMode: WaitForFirstConsumer, this waits until a Pod that uses the claim is scheduled. A later chapter covers this.
Common errors
- Class mismatch. A claim with no
storageClassNameuses the cluster's default class. A claim withstorageClassName: ""asks for a PV with no class. These are different requests. - Access mode mismatch. A claim for
ReadWriteManywill not bind to aReadWriteOncevolume. - Claim larger than every PV. The claim stays
Pending. - Reused PV. A
Retained PV that has been released keeps its oldclaimRef. It staysReleasedand won't bind to a new claim until an administrator clears that reference.
Exercise
A PVC requests 5Gi with ReadWriteOnce and storageClassName: manual. The cluster has one unbound PV with 10Gi, ReadWriteOnce, and storageClassName: manual. Does the claim bind, and how much storage does the claim effectively hold?
Show answer
Yes, it binds, because the class and access mode match and the 10Gi capacity is at least the 5Gi request. The binding is one-to-one, so the claim holds the whole 10Gi volume, and no other claim can use the remaining 5Gi.