Sub topic 4
PersistentVolumeClaims: requesting storage
This chapter assumes you can apply YAML with kubectl and that you know what a PersistentVolume (PV) is from the previous chapter. A PersistentVolumeClaim (PVC) is how a workload asks for storage without knowing where that storage lives.
The working model
A PV is supply. A PVC is demand. You describe what you need (size, access mode, class), and Kubernetes finds a PV that satisfies it and binds the two together. The claim is namespaced. The PV is cluster-wide.
A minimal claim
This claim requests 1Gi of ReadWriteOnce storage from the class named manual. It can bind to the PV demo-pv from the previous chapter.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: demo-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: manual
resources:
requests:
storage: 1GiThe important fields are:
accessModes: how the volume may be mounted. The PV must offer this mode.storageClassName: the class to match. A PV with the same class name is a candidate.resources.requests.storage: the minimum size. A PV of equal or larger capacity can satisfy it.
Inspecting a claim
Apply the manifest, then check its status.
kubectl get pv
kubectl get pvc
kubectl describe pvc demo-pvcA bound claim shows STATUS as Bound and names the PV under VOLUME. A claim that shows Pending has not found a match yet. The Events section of kubectl describe usually says why.
Details that cause surprises
- The claim must be in the same namespace as the Pod that uses it. Pods cannot reference a claim in another namespace.
- Binding is one to one. If a 10Gi PV satisfies a 1Gi claim, the claim gets all 10Gi of capacity and no other claim can use that PV.
- The
storageClassNamemust match exactly. Omitting the field selects the cluster's default class, which may be a different outcome. Setting it to""asks for a PV with no class. - The request is a minimum. The claim does not cap usage below the volume's real size.
Claims and Pods
A claim does nothing on its own. A Pod uses it through spec.volumes, with persistentVolumeClaim.claimName set to the claim's name. The next chapters cover access modes and binding in more detail, and then how to mount the claim in a Pod.
Exercise
You apply a PVC requesting 5Gi with storageClassName: manual. The only PV with that class has 3Gi capacity. What status does the claim show, and where do you look to find out why?
Show answer
The claim stays Pending, because no PV with a matching class has at least 5Gi. Run kubectl describe pvc <name> and read the Events section.