PersistentVolumes, PVCs & StorageClass
PersistentVolume (PV) is the actual storage. PersistentVolumeClaim (PVC) is a request for storage. StorageClass enables dynamic provisioning.
PV = a storage unit at a facility. PVC = a rental agreement ('I need 10GB, read-write'). StorageClass = the facility manager who auto-assigns units. You sign the agreement (PVC), the manager (StorageClass) finds or builds you a unit (PV).
Workflow: (1) Admin creates PV (or StorageClass for dynamic provisioning). (2) User creates PVC requesting size, access mode, and StorageClass. (3) Kubernetes binds the PVC to a matching PV. (4) Pod mounts the PVC as a volume. Access modes: ReadWriteOnce (one node), ReadOnlyMany (many nodes read), ReadWriteMany (many nodes read+write), ReadWriteOncePod (one pod, K8s 1.22+). Reclaim policies: Retain (manual cleanup), Delete (auto-delete PV when PVC deleted), Recycle (deprecated).
Dynamic provisioning: StorageClass defines a provisioner (kubernetes.io/aws-ebs, kubernetes.io/gce-pd, driver.longhorn.io). When a PVC is created with a StorageClass, the provisioner automatically creates the PV and underlying storage. volumeBindingMode: WaitForFirstConsumer delays PV provisioning until a pod requests the PVC — ensures the PV is created in the same availability zone as the pod. Volume snapshots (CSI): VolumeSnapshot API for backup workflows. CSI (Container Storage Interface) is the plugin standard — all major storage vendors implement CSI drivers. Local volumes: hostPath (development only) vs local PV (production, uses specific node paths, requires nodeAffinity on the PV).
PVCs are how applications request storage without knowing the backend. The separation of PV (infrastructure concern) from PVC (application concern) is intentional — developers write PVCs, admins or StorageClasses handle PVs. In cloud environments, use a StorageClass with dynamic provisioning — EBS for AWS, PD for GCP. Use WaitForFirstConsumer binding mode to ensure the PV lands in the same availability zone as the pod. For databases, ReadWriteOnce with a block storage PV is the standard — it gives performance comparable to a local disk.
ReadWriteOnce means one node, not one pod. Multiple pods on the same node can mount an RWO volume simultaneously. For single-pod exclusivity, use ReadWriteOncePod (K8s 1.22+). Also, scaling a StatefulSet down does NOT release PVCs — they remain bound and billing continues.