Skip to content
Visual explainer 3h to learn 4 steps

PersistentVolumes, claims, access modes & reclaim policies

Bind a PVC to a PV and fix claims stuck in Pending.

By Invicly Tech, , in Kubernetes Administrator (CKA). About 10 minutes to read.

Topic 24 of 33

In short

A PersistentVolume is a piece of storage in the cluster, and a PersistentVolumeClaim is a request for storage by a user. The control plane binds a claim to a PV that matches its size, access mode and storage class. The reclaim policy decides what happens to the PV after the claim is deleted.

Explained simply

Some data must outlive Pods: database files, uploads, queues. Kubernetes separates the storage itself from the request for it, so that app teams do not need to know whether the disk is NFS, a cloud disk or something else.

A PersistentVolume (PV) is a real piece of storage that the cluster knows about, like a 10 GB disk. An admin creates it, or a provisioner creates it automatically. PVs belong to the whole cluster, not to any namespace.

A PersistentVolumeClaim (PVC) is a request from an app team: "I need 5 GB, read-write, from the fast class". Kubernetes finds a PV that fits and binds them together, one claim to one volume. The Pod then just names the claim.

When the claim is deleted, the reclaim policy decides the PV's fate. Delete removes the storage. Retain keeps the data for a human to look at and clean up. Choosing wrong can mean losing a database, so check this setting.

Press Play on a diagram to walk through it one step at a time.

FlowStatic provisioning lifecycle
  1. 1
    Admin creates PV

    Capacity, access modes, storageClassName, backend.

  2. 2
    User creates PVC

    Requests size, access mode and class.

  3. 3
    Bound

    Controller binds PVC to a matching PV one-to-one.

  4. 4
    Pod mounts PVC

    References the claim by name in volumes.

  5. 5
    PVC deleted

    Retain keeps PV Released; Delete removes it.

CompareAccess modes and reclaim
Access modes
  • RWO: one node read-write
  • ROX: many nodes read-only
  • RWX: many nodes read-write
  • RWOP: one Pod read-write
Reclaim policies
  • Retain: keep data, manual cleanup
  • Delete: remove PV and backend
  • Recycle: deprecated
LayersFrom Pod down to disk
  1. 1
    Pod

    volumes: persistentVolumeClaim: claimName

  2. 2
    PersistentVolumeClaim

    Namespaced request: size, mode, class

  3. 3
    PersistentVolume

    Cluster-scoped, bound one to one

  4. 4
    Volume plugin or CSI driver

    Attaches and mounts on the node

  5. 5
    Real storage

    Cloud disk, NFS share, local disk

In depth

The exact binding rules

A controller in kube-controller-manager looks for a PV that satisfies the claim. The storageClassName must be equal: a PV with no class only matches a PVC whose class is explicitly empty (""). Capacity must be at least the request, and the PV's access modes must include every mode the claim asks for. volumeMode (Filesystem or Block) must match, and a selector on the claim must match the PV's labels.

Among matching PVs it picks the smallest that fits. If the PV is bigger than the request, the claim gets all of it: a 500Mi claim bound to a 1Gi PV shows capacity 1Gi. Binding is exclusive, so the rest is never shared. To force a specific pairing, set spec.volumeName on the PVC, and optionally claimRef on the PV to reserve it.

FlowDoes this PV fit this PVC?
  1. 1
    Same storageClassName?

    Empty only matches explicit ""

  2. 2
    Access modes covered?

    PV must include all requested modes

  3. 3
    Capacity big enough?

    PV size at least the request

  4. 4
    volumeMode and selector

    Filesystem or Block; labels match

  5. 5
    Bind smallest match

    claimRef and volumeName set, both Bound

Access modes are about nodes

ReadWriteOnce (RWO) means one node may mount the volume read-write. Several Pods on that same node can still share it, which surprises many people. ReadOnlyMany (ROX) lets many nodes mount it read-only, ReadWriteMany (RWX) lets many nodes write, and ReadWriteOncePod (RWOP, stable since 1.29) allows exactly one Pod in the whole cluster.

The backend decides what is possible. Block storage like cloud disks is usually RWO only; file storage like NFS or CephFS supports RWX. A PV can list several modes, but a given mount uses one. Asking for RWX from a class that cannot provide it leaves the claim Pending or fails at provisioning, with the reason in the events.

  • RWO: one node, many Pods on it allowed
  • RWOP: one Pod, cluster wide
  • RWX needs a shared file system such as NFS

Phases, protection and reclaiming

A PV moves through Available, Bound, Released (its claim was deleted) and Failed. A PVC is Pending, Bound or Lost (its PV disappeared). Two finalizers stop accidents: kubernetes.io/pvc-protection keeps a PVC in Terminating while any Pod still uses it, and kubernetes.io/pv-protection keeps a bound PV from being removed.

With Retain, a Released PV keeps its data but will not bind again, because claimRef still points to the deleted claim. After you have saved or wiped the data, remove claimRef and the PV becomes Available. With Delete, the PV and the backing storage are removed, which is the default for dynamically provisioned volumes. Recycle, a basic wipe, is deprecated.

  • kubectl patch pv NAME -p '{"spec":{"claimRef":null}}' makes it Available again
  • kubectl patch pv NAME -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}' protects it
  • kubectl get pv shows STATUS and CLAIM as namespace/name
CycleLife of a Retain PV
  1. 1
    Available

    Created, waiting for a claim

  2. 2
    Bound

    Claim and Pod use it

  3. 3
    Released

    Claim deleted, data kept

  4. 4
    Admin cleans up

    Back up or wipe, clear claimRef

  5. Back to step 1

Fixing a PVC stuck in Pending

Start with kubectl describe pvc and read the events. no persistent volumes available for this claim and no storage class is set means static binding found nothing: compare class, size and access modes with kubectl get pv. If the claim has no storageClassName and the cluster has a default class, the default is filled in automatically, so it will never bind to a manual PV that has no class. That is the most common exam trap.

If the event says waiting for first consumer, the class uses WaitForFirstConsumer and the claim binds only after a Pod using it is scheduled. A Pod whose claim is not bound stays Pending too, with an event about unbound PersistentVolumeClaims, so always check the claim before the Pod.

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Create a PersistentVolume~45m
  2. 2
    Bind it with a PersistentVolumeClaim~45m
  3. 3
    Compare access modes and reclaim policies~45m
  4. 4
    Fix a PVC stuck in Pending~45m

Key points

  • PVs are cluster-scoped; PVCs are namespaced.
  • Binding needs matching storageClassName, enough capacity and a supported access mode.
  • A Pending PVC usually has no matching PV or a class mismatch.
  • A Released PV with Retain cannot rebind until you clear its claimRef.

Key terms

Tap a card to flip it. 0/5 known

Examples

yaml
apiVersion: v1
kind: PersistentVolume
metadata: { name: pv-data }
spec:
  capacity: { storage: 1Gi }
  accessModes: [ReadWriteOnce]
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  hostPath: { path: /mnt/data }  # lab only
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata: { name: data, namespace: app }
spec: { storageClassName: manual, accessModes: [ReadWriteOnce],
  resources: { requests: { storage: 500Mi } } }

A claim that ignores your PV

You created PV pv-data with storageClassName manual, and a PVC with no class at all. The PVC binds to a brand-new volume instead, or stays Pending. Step 1: check the PVC's class; it says standard, the default, filled in at creation. Step 2: the class field cannot be changed on an existing claim, so delete and recreate it with storageClassName: manual. Step 3: confirm both show Bound and point to each other.

bash
kubectl -n app get pvc data -o jsonpath='{.spec.storageClassName}'; echo  # standard
kubectl get storageclass                    # standard (default)
kubectl -n app delete pvc data
# recreate with: storageClassName: manual
kubectl apply -f pvc.yaml
kubectl get pv pv-data                      # STATUS Bound, CLAIM app/data
kubectl -n app get pvc data                 # VOLUME pv-data

Reusing a Released PV

A team deleted its PVC, and the Retain PV now shows Released. They want the same data back under a new claim. Step 1: confirm the status. Step 2: remove the stale claimRef so the PV becomes Available. Step 3: create a new PVC that pins the PV with volumeName. Step 4: mount it in a Pod and check the old files are there.

bash
kubectl get pv pv-data                       # Released
kubectl patch pv pv-data -p '{"spec":{"claimRef":null}}'
kubectl get pv pv-data                       # Available
# new PVC spec: storageClassName: manual, volumeName: pv-data,
#   accessModes: [ReadWriteOnce], resources.requests.storage: 1Gi
kubectl apply -f pvc-again.yaml
kubectl get pv pv-data                       # Bound

Quick reference

  • PVs are cluster-scoped; PVCs are namespaced; binding is one to one
  • A PVC with no class gets the default class; use storageClassName: "" or a name to bind static PVs
  • Pin a claim to a PV with spec.volumeName on the PVC
  • RWO means one node, not one Pod; RWOP means one Pod
  • Released PV with Retain: clear spec.claimRef to make it Available
  • PVC stuck Terminating: a Pod still uses it (pvc-protection finalizer)
  • There is no kubectl create pv; copy the YAML from the docs page

Common mistakes

  • Leaving storageClassName empty on the PVC so the default class provisions a new volume.
  • Requesting RWX from a backend that only supports RWO.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1A 500Mi PVC binds to a 2Gi PV. What capacity does the PVC show?

Question 2

2Two Pods on the same node mount one RWO volume. What happens?

Question 3

3You delete a PVC that a running Pod uses. What do you see?

Question 4

4A Retain PV is Released. Why does a new matching PVC not bind to it?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Create a hostPath PV pv-log (1Gi, RWO, class manual, path /mnt/log) and a PVC log-claim in default requesting 200Mi from class manual. Show they are bound.

  2. Exercise 2medium

    Mount log-claim in a Pod at /var/log/app, write a file, delete the Pod, start a new Pod on the same node and show the file survived.

  3. Exercise 3hard

    A PVC db-data in namespace prod is Pending. Find out why and fix it without changing the existing PV.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Why is my PVC stuck in Pending?
No PV matches its class, size and access mode, or its class uses WaitForFirstConsumer and no Pod uses it yet. kubectl describe pvc shows which.
Can I resize a PVC?
You can grow it by editing spec.resources.requests.storage if its StorageClass has allowVolumeExpansion: true. Shrinking is not supported.
Does deleting a Pod delete its PVC?
No. The claim and its data stay until you delete the PVC. Even then, a Retain policy keeps the PV and its data.

Go deeper

ShareXLinkedInWhatsApp