PersistentVolumes and PersistentVolumeClaims
Storage that outlives Pods: how PVs and PVCs split supply from demand, how binding picks a volume, access modes, reclaim policies and protections.
PersistentVolumes and PersistentVolumeClaims
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A PersistentVolume is a piece of real storage registered in the cluster. A PersistentVolumeClaim is a namespaced request for storage. Pods mount claims, never volumes directly.
- The PV controller binds each claim to one matching volume (class, access modes, size, selector), the smallest that fits, and the binding is exclusive and one-to-one.
- Access modes describe how many nodes may mount: ReadWriteOnce (one node), ReadOnlyMany, ReadWriteMany, and ReadWriteOncePod (one Pod in the whole cluster).
- When a claim is deleted, the reclaim policy decides the volume's fate: Delete removes the storage, Retain keeps it as Released until an admin clears it.
- Protection finalizers keep a claim in use from being deleted out from under a Pod, and since 1.37 an Unused condition marks claims no Pod references.
Data that has to survive the Pod
An emptyDir dies with its Pod. A database can’t. Its data has to survive the Pod being deleted, rescheduled to another node, or replaced in a rollout, and that means storage that lives outside any node: a cloud disk, an NFS export, a SAN LUN, a Ceph volume.
There are two people with different concerns here. The app developer knows they need “20 GiB of fast disk that one Pod writes to”. The cluster admin, or the cloud, knows which storage systems exist and how to reach them. Kubernetes separates the two with a pair of objects: the PersistentVolume (supply) and the PersistentVolumeClaim (demand). Think of a hotel. Rooms exist whether or not anyone has booked them. A guest asks for “a double, non-smoking, two nights” and the front desk assigns a specific room. The guest never deals with room inventory directly.
The two objects
A PV describes real storage and is cluster-scoped:
apiVersion: v1
kind: PersistentVolume
metadata: {name: nfs-small}
spec:
capacity: {storage: 5Gi}
accessModes: [ReadWriteMany]
persistentVolumeReclaimPolicy: Retain
storageClassName: manual
nfs: {server: 10.0.0.20, path: /exports/small}
A PVC is a request, namespaced with the app:
apiVersion: v1
kind: PersistentVolumeClaim
metadata: {name: uploads, namespace: storage}
spec:
accessModes: [ReadWriteMany]
storageClassName: manual
resources: {requests: {storage: 3Gi}}
A Pod mounts the claim by name, never the PV, so the Pod spec stays the same whether the storage is NFS on-prem or a cloud disk:
volumes:
- name: u
persistentVolumeClaim: {claimName: uploads}
How binding works
The PV controller in kube-controller-manager matches claims to volumes. A volume qualifies when its storageClassName matches, it offers every requested access mode, its capacity is at least the request, and it matches the claim’s selector if one is set. Among those it picks the smallest. We created a 5Gi and a 50Gi PV and a 3Gi claim on the lab cluster. Within seconds the claim was Bound to nfs-small, reporting a capacity of 5Gi, not 3. Binding is whole-volume and exclusive: the PV records the claim in spec.claimRef, the claim records the PV in spec.volumeName, and no one else can use the leftover 2Gi.
If nothing matches, the claim waits in Pending and the controller keeps retrying as PVs appear. To pin a claim to a particular volume, set volumeName on the claim, or pre-fill claimRef on the PV. Setting storageClassName: "" explicitly asks for a PV with no class and opts out of dynamic provisioning, which is the next lesson and how most clusters work today.
Access modes
Access modes say how a volume may be mounted, and they’re about nodes, not Pods:
ReadWriteOnce(RWO): read-write by a single node. Several Pods on that node can share it. Most block storage, such as cloud disks, is RWO.ReadOnlyMany(ROX): read-only by many nodes.ReadWriteMany(RWX): read-write by many nodes. Needs a shared filesystem such as NFS, EFS, Azure Files or CephFS.ReadWriteOncePod(RWOP, GA since 1.29): read-write by exactly one Pod in the whole cluster, for when even two Pods on the same node would corrupt data.
A Deployment with two replicas and one RWO claim is the classic trap: the second Pod lands on another node and hangs waiting for an attach that can’t happen. StatefulSets give each replica its own claim instead.
Releasing a volume: reclaim policies
Deleting a claim doesn’t necessarily delete data. The PV’s persistentVolumeReclaimPolicy decides:
Delete: the storage itself is deleted. This is the default for dynamically provisioned volumes.Retain: the PV becomesReleasedand keeps its data, and its oldclaimRef, until an admin deals with it.Recycle(a basicrm -rf) is deprecated. Don’t use it.
The Retain behaviour surprised us in a useful way. We deleted the uploads claim and then created an identical uploads2. It did not get the freed 5Gi volume. It bound to the 50Gi one, because nfs-small sat in Released with its claimRef still naming the deleted claim. That’s deliberate: a Released volume holds someone’s data, and Kubernetes won’t hand it to a stranger. Removing spec.claimRef with a patch moved it back to Available (and updated its lastPhaseTransitionTime), at which point it could bind again.
Protection against accidents
Two finalizers stop the most damaging mistakes. Every claim gets kubernetes.io/pvc-protection. When we deleted uploads while a Pod still mounted it, the claim sat in Terminating and was only removed once the Pod was gone. PVs get kubernetes.io/pv-protection for the same reason while bound.
Orphaned claims are the opposite problem: Pods are deleted, claims stay, and the bill keeps coming. Since 1.37 (beta, on by default), the PVC protection controller sets an Unused condition. On our lab, uploads2, which no Pod referenced, showed {"type":"Unused","status":"True","reason":"NoPodsUsingPVC","message":"No pods are currently referencing this PVC"}, with lastTransitionTime telling you since when. That makes finding forgotten volumes a single query.
About the video
The embed is a 13-minute clip, 0:20 to 13:40, of TechWorld with Nana’s “Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class” from May 2020. The clip covers why apps need persistent storage, PersistentVolumes, local against remote volume types, who creates PVs and when (the admin and user roles), PersistentVolumeClaims, and the levels of abstraction and why they help. That’s this lesson’s model. It’s from 2020, so it doesn’t mention ReadWriteOncePod, the CSI-first world or the 1.37 Unused condition. Its StorageClass chapter is next lesson’s topic. Judged from chapters, since transcripts can’t be fetched here. It has no audio-track flag and an English caption track. Piyush’s 2024 episode in deeper includes a static provisioning demo.
What was run: against a local v1.37.3 control plane with no kubelet, we created the two NFS PVs and the claim and watched the real PV controller bind the smallest fit, deleted the claim under a Pod to see pvc-protection hold it, watched the Retain volume go Released and the next claim skip it, cleared the claimRef to make it Available, and read the Unused condition. Nothing was mounted and no NFS server existed. Access-mode and reclaim semantics are from the persistent volumes docs, checked 2026-11-28.
Where this fits
Creating PVs by hand doesn’t scale past a few apps. Next: StorageClasses, CSI and dynamic provisioning.
Check yourself
A 3Gi claim binds to a 5Gi volume. How much space does the Pod get, and why wasn't a 3Gi volume created?
5Gi. With static provisioning the controller can only choose among existing volumes, and it picks the smallest one that satisfies the request. Binding is whole-volume and exclusive, so the extra 2Gi is unusable by anyone else.
You delete a claim whose PV has reclaim policy Retain, then create a new identical claim. It doesn't bind to the old volume. Why?
The PV is Released and still has a claimRef to the deleted claim's UID, so it won't bind to anything else. That protects the old data. An admin must inspect it and remove spec.claimRef (or recreate the PV) to make it Available again.
Two replicas of a Deployment share one ReadWriteOnce claim. One Pod runs, the other is stuck ContainerCreating on another node. Why?
ReadWriteOnce means mountable read-write by one node at a time. A block device such as an EBS volume can attach to only one node. Both Pods on the same node would work. For per-replica storage use a StatefulSet; for shared storage use a ReadWriteMany volume such as NFS or EFS.
kubectl delete pvc data hangs with the claim in Terminating. What is happening?
The kubernetes.io/pvc-protection finalizer holds the deletion while a Pod still uses the claim. Once the Pods using it are gone, the finalizer is removed and the claim is deleted, then the PV is handled by its reclaim policy.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.