Storage: PV/PVC/StorageClass, CSI, access modes, expansion, reclaim policies

Claim binds to a volume, volume attaches to the node, kubelet mounts it into the pod. WaitForFirstConsumer is what stops the volume landing in the wrong zone.

Read the briefing
About 4 min to read 7 drills

What to remember

  1. Bind, attach, mount — three steps, three failure modes. Pending claim, attach error, mount error. The events name which.
  2. WaitForFirstConsumer or zone deadlock. Bind the volume after scheduling, or the pod and the disk end up in different zones.
  3. ReadWriteOnce means one node, not one pod. Multiple pods on the same node can share it; a rolling update across nodes cannot.
  4. reclaimPolicy Delete deletes real data. Retain for anything you would miss. This is a one-line decision with permanent consequences.
  5. Expansion is online for many drivers, but never shrinking. Plan sizes with growth; you cannot go back.

The big picture

Kubernetes storage is a chain of objects that turns "this pod needs 50 GiB that survives restarts" into a real volume attached to the right node: PersistentVolumeClaim → StorageClass → provisioner (CSI driver) → PersistentVolume → mount. Almost every storage incident is one link in that chain refusing, and almost every data-loss story is a reclaim or retention policy someone did not read.

The mental model

A PVC is a request, a PV is a supply, and the StorageClass is the vending machine that turns requests into supply on demand. Binding pairs a request with a supply; the CSI driver does the physical attach and mount on the node. Two independent lifecycles decide what happens to data: the StatefulSet's PVC retention policy (does the claim survive the set) and the StorageClass's reclaimPolicy (does the volume survive the claim).

In depth

The object chain and where it breaks

A pod references a PersistentVolumeClaim by name. The claim names a StorageClass (or inherits the default), an access mode, and a size. The class names a provisioner (a CSI driver such as ebs.csi.aws.com, pd.csi.storage.gke.io, or the DigitalOcean block storage driver) and parameters (disk type, IOPS, encryption). When the claim is created, the external provisioner creates a PersistentVolume and binds it; the pod can then be scheduled, the CSI controller attaches the volume to the node, and the CSI node plugin mounts it into the pod.

Each hop has a failure signature. Claim Pending with no PV: the class does not exist, the provisioner is down, or the quota is exhausted (kubectl describe pvc says which). Pod Pending with unbound immediate PersistentVolumeClaims: the PVC is still pending. Pod stuck ContainerCreating with FailedAttachVolume or FailedMount: the volume is attached elsewhere (a previous node has not released it), the node lacks the driver, or the filesystem needs a repair. Multi-Attach error means an RWO volume is still attached to a node that did not detach cleanly, often after a node failure.

Access modes, binding modes, and topology

ReadWriteOnce (one node at a time; the common block-storage case), ReadOnlyMany, ReadWriteMany (needs a shared filesystem such as NFS/EFS/Filestore or a CSI driver that supports it), and ReadWriteOncePod (one pod, enforced). Access modes describe what the storage can do, not a promise Kubernetes enforces for RWO across pods on the same node.

volumeBindingMode: WaitForFirstConsumer defers provisioning until a pod is scheduled so the volume lands in the pod's zone; Immediate provisions at claim time and can create a volume in a zone where the pod cannot run. Zonal block storage makes pods immobile across zones: a pod whose PV is in us-east-1a can only ever schedule there, which is why StatefulSets spread across zones need per-zone awareness and why "just move the pod" is not an answer.

Two lifecycles that decide whether data survives

reclaimPolicy on the StorageClass (inherited by the PV) governs the PV after its PVC is deleted: Delete destroys the underlying disk; Retain keeps it (the PV goes to Released and must be manually cleaned or re-bound). Dynamic classes default to Delete.

persistentVolumeClaimRetentionPolicy on a StatefulSet governs the PVCs when the set is deleted or scaled down: Retain (default) keeps them; Delete removes them. The two compose: with StatefulSet Retain and class Delete, deleting the StatefulSet keeps the claims and the data; deleting a claim afterwards destroys the disk. Volume expansion (allowVolumeExpansion: true) grows a PVC in place; shrinking is not supported. Snapshots (VolumeSnapshot) are the backup primitive for block volumes, but a snapshot of a running database is only consistent if the database is quiesced or crash-consistent by design.

Myths and facts

Myth: Deleting a pod deletes its PersistentVolumeClaim.

Fact: PVCs are independent objects; pods only reference them. StatefulSet-created PVCs survive pod deletion and, by default, set deletion.

Myth: ReadWriteOnce means only one pod can use the volume.

Fact: RWO is node-scoped: multiple pods on the same node can mount it. ReadWriteOncePod is the pod-scoped mode.

Myth: The StorageClass reclaimPolicy decides what happens when I delete a StatefulSet.

Fact: That is the StatefulSet's persistentVolumeClaimRetentionPolicy. reclaimPolicy applies after the PVC itself is deleted.

Myth: A Pending PVC means the cluster is out of disk.

Fact: Usually the class name is wrong, the provisioner is unhealthy, or binding is waiting for a consumer. describe pvc names the reason.

Myth: Kubernetes will move my pod and its disk to another zone if the node dies.

Fact: Zonal volumes pin the pod to the zone. Recovery across zones needs replication at the application layer or a regional storage class.

How pros do it

  • Set a default StorageClass and reference classes explicitly in production manifests; a typo in storageClassName is a Pending workload.
  • Use WaitForFirstConsumer for zonal block storage so volumes are created where the pod can run.
  • Decide the two lifecycles on purpose: reclaimPolicy Retain for data you cannot recreate, and a documented StatefulSet PVC retention policy.
  • Enable allowVolumeExpansion and alert on PVC usage (kubelet_volume_stats_used_bytes / capacity) before 85%.
  • Back up with VolumeSnapshots plus application-level dumps; test a restore into a scratch namespace before you need it.

Questions people ask

My PVC is Pending. Where do you look?

kubectl describe pvc — the message names the link that refused. 'storageclass not found' means the class name is wrong or missing; 'waiting for first consumer to be created before binding' is not an error, the volume is created when a pod using the claim is scheduled; a provisioner error means the CSI driver or the cloud said no. If the pod is Pending too, read the pod's events next.

How do I run a database on Kubernetes safely?

StatefulSet with volumeClaimTemplates, a class with Retain and WaitForFirstConsumer, per-zone awareness, PDBs, snapshots plus logical backups tested by restoring into a scratch namespace, and an operator if one exists for the engine. Say the two lifecycles: the set's PVC retention policy and the class's reclaimPolicy.

Why does my pod on a new node say Multi-Attach error for an RWO volume?

The volume is still attached to the old node, usually because that node died without detaching. Confirm the old pod is gone and whether the node is still registered; the attach/detach controller force-detaches six minutes after the pod is gone from an unhealthy or deleted node (immediately with the out-of-service taint), and if the cloud refuses to detach from a dead instance, force it through the cloud API.

What is the difference between a PV and a PVC?

A PV is the cluster-scoped piece of storage (supply); a PVC is a namespaced request that binds one-to-one to a PV. Pods reference claims, never volumes directly, and a StorageClass is what turns a claim into a PV on demand.

Can I resize a volume down?

No. Expansion works when the class sets allowVolumeExpansion; shrinking is not supported. Create a smaller volume and copy, and plan sizes with growth.

Further reading

Drills · 7

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

'My PVC has been Pending for ten minutes.' It names storageClassName: fast-ssd, and kubectl describe pvc shows storageclass.storage.k8s.io "fast-ssd" not found. What is wrong, and what do you tell the developer?

  1. PVCs must be created by an administrator. PVCs are namespaced and routinely created by application manifests.
  2. The cluster is out of disk space. Capacity problems surface as provisioner errors, not as a missing class.
  3. The pod has not been created yet, so binding waits. That message would say 'waiting for first consumer'; this one says the class does not exist.
  4. No StorageClass with that name exists, so no provisioner is asked to create a volume; fix the class name or create the class. Dynamic provisioning is driven by the class; an unknown class means nothing happens.
In short

No StorageClass named fast-ssd exists, so nothing provisions a volume; fix the class name or create the class.

Why

The PVC names the class; the class names the provisioner. When the class is missing, the request is never routed anywhere and the claim sits Pending forever. kubectl get storageclass lists what exists and which one is default.

The common mistake

Guessing 'the cluster is out of disk'. Capacity problems show up as provisioner errors; a missing class means the request was never routed anywhere.

Read the docs

2 Answer out loud

Walk me through what happens between a pod referencing a PersistentVolumeClaim and the volume being mounted. Then: which two policies decide whether the data survives deleting the StatefulSet? Four to six sentences.

In short

A strong answer walks claim, class, provisioner, bind, attach, mount, then names the StatefulSet PVC retention policy and the class reclaimPolicy.

What a strong answer does
  • mechanism: PVC references a class; the CSI provisioner creates a PV and binds; scheduler places the pod (WaitForFirstConsumer respects zone); CSI controller attaches, node plugin mounts; failure signatures per hop.
  • lifecycles: Explains that retention governs PVCs on set deletion/scale-down and reclaim governs the PV after the PVC is deleted, and how they compose.
  • communication: Chain in order, then the two policies with a one-line composition rule.
Why

Interviewers want the chain in order with failure signatures, and the two-lifecycle distinction stated crisply; candidates who blur retention and reclaim have usually lost data or will.

The common mistake

Blurring reclaim and retention, or saying 'deleting the StatefulSet deletes the data'. By default the claims survive the set; the disk goes only when the claim goes and the class says Delete.

3 Pick the strongest answer

A Deployment with two replicas shares one RWO PVC and its rolling update keeps failing with Multi-Attach errors, yet two pods on the same node once shared that volume fine. Which statement about ReadWriteOnce is correct?

  1. RWO is only available for NFS-backed volumes. Block storage (EBS, PD, DO volumes) is the classic RWO case.
  2. RWO allows the volume to be mounted read-write by a single node; multiple pods on that node can still use it. ReadWriteOncePod restricts it to one pod. Access modes are node-scoped; the pod-scoped guarantee is a separate mode.
  3. RWO guarantees only one pod anywhere in the cluster can write. That is ReadWriteOncePod. RWO is enforced per node.
  4. RWO volumes can be mounted on many nodes as long as only one writes. Multi-node mounting is ReadOnlyMany or ReadWriteMany.
In short

RWO means one node at a time; several pods on that node can share it, and ReadWriteOncePod is the one-pod mode.

Why

Access modes describe the storage's capabilities. Block devices attach to one node at a time, hence RWO; shared filesystems can offer RWX. ReadWriteOncePod exists because RWO surprised people who assumed pod-level exclusivity.

Read the docs

4 Read the output

What happens to the 20 GiB disk behind data-redis-1, and why?

$ kubectl get sc standard -o jsonpath='{.reclaimPolicy}'
Delete
$ kubectl get sts redis -o jsonpath='{.spec.persistentVolumeClaimRetentionPolicy}'
{"whenDeleted":"Retain","whenScaled":"Retain"}
$ kubectl delete sts redis
statefulset.apps "redis" deleted
$ kubectl get pvc
NAME                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS
data-redis-0        Bound    pvc-3b1c...                                20Gi       RWO            standard
data-redis-1        Bound    pvc-9f02...                                20Gi       RWO            standard
$ kubectl delete pvc data-redis-1
  1. It is kept as a Released PV that can be re-bound. That is reclaimPolicy Retain; this class is Delete.
  2. It is detached but preserved for 7 days by default. There is no built-in grace period; reclaim is immediate.
  3. It is destroyed: the StatefulSet policy kept the PVC, but deleting the PVC triggers the class's reclaimPolicy Delete. Two lifecycles: the set's retention policy protected the claim; the class's reclaim policy governs what happens once the claim is gone.
  4. Nothing yet; disks are deleted only when the namespace is deleted. PV reclaim happens when the bound PVC is deleted, regardless of namespace.
In short

The disk is deleted: the StatefulSet kept the PVC, but deleting the PVC triggers the class's reclaimPolicy Delete.

Why

Read both policies before deleting anything stateful. The StatefulSet's persistentVolumeClaimRetentionPolicy decided that deleting the set keeps the claims; the StorageClass's reclaimPolicy: Delete decides that deleting a claim deletes the disk. Retain on the class is the safety net for data you cannot recreate.

Read the docs

5 Find what's broken

This class backs the production Postgres StatefulSet in a three-zone cluster. Three lines will each cause an incident — which, and what do you change?

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: db-ssd
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  encrypted: "true"
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-postgres-0
spec:
  accessModes: [ReadWriteOnce]
  storageClassName: db-ssd
  resources:
    requests:
      storage: 200Gi
In short

Lines 9, 10 and 11 are wrong: reclaimPolicy Delete, Immediate binding in a multi-zone cluster, and no volume expansion.

What's broken
  • Line 9: reclaimPolicy Delete on the production database class: deleting a claim (or a namespace) destroys the data disk.
  • Line 10: Immediate binding provisions the EBS volume in an arbitrary zone at claim time; the pod may be unable to schedule in that zone.
  • Line 11: allowVolumeExpansion false means the 200Gi claim cannot be grown when the database fills; the only path is a migration.
Why

Three settings that are fine for scratch volumes and wrong for a database: Delete reclaim, Immediate binding in a multi-zone cluster, and no expansion. gp3 with encryption (lines 7–8) is fine; RWO (line 18) is correct for a single-writer database. Interviewers like this because every line looks reasonable in isolation.

Read the docs

6 Scenario: what do you do next?

An RPC node rpc-2 (StatefulSet, 2 TiB block volume for the ledger) was on a node that failed hard. The pod was recreated on another node and is stuck ContainerCreating for 9 minutes with Multi-Attach error for volume "pvc-…": Volume is already exclusively attached to one node and can't be attached to another. The other two RPC nodes are serving; slot lag on the fleet is rising.

Step 1. First move?

  1. Confirm the old pod is truly gone (kubectl get pod -o wide, kubectl get volumeattachment | grep pvc-…) and whether the failed node is still registered (NotReady) or already deleted; the block volume is still recorded as attached to it. The error names the mechanism: RWO block storage cannot attach to two nodes. Evidence first tells you whether the old attachment is stale.
  2. Switch the StorageClass to ReadWriteMany. Block storage does not become shareable by editing a class; and existing volumes do not change.
  3. Scale the StatefulSet to zero and back. It recreates the same pod with the same stale attachment problem.
  4. Delete the PVC so the StatefulSet makes a fresh one. That destroys 2 TiB of ledger; re-syncing takes hours.

Step 2. The VolumeAttachment still points at the dead node and the node object is gone. Mitigation?

  1. Cordon the new node and let the pod land elsewhere. Any node will hit the same stale attachment.
  2. Wait; the controller will detach after six minutes. It already tried: the attach/detach controller force-detaches six minutes after the pod is gone from an unhealthy or deleted node, and this pod has been stuck for nine. What remains is the cloud refusing to detach from a failed instance, which does not resolve by waiting.
  3. Force the detach through the cloud API (detach the volume from the dead instance), then clear the stale VolumeAttachment if its finalizer is still holding it, so the attach-detach controller can attach to the new node; meanwhile keep rpc-2 out of the load balancer pool. At nine minutes the controller's own six-minute force-detach has already fired and failed against the dead instance; the cloud-side detach is what is stuck, so that is the targeted, reversible fix while the LB protects clients.
  4. Restart the CSI controller. The controller is doing its job; the stale record is the problem.

Step 3. Attached, mounted, catching up. Postmortem action?

  1. Stop using StatefulSets for RPC nodes. Stable identity plus per-replica storage is exactly what RPC nodes need.
  2. A runbook plus alert for VolumeAttachments pointing at nodes that no longer exist, node auto-repair that drains before replacement, and a fleet design where one RPC node being down does not breach the SLO. Detects the failure mode, prevents the common cause, and sizes the fleet so the blast radius is tolerable.
  3. Move the ledger to an RWX filesystem so any node can mount it. Shared filesystems cannot deliver the IOPS and latency a ledger needs; the fix is operational, not architectural.
In short

Confirm the old attachment is stale, then force the detach through the cloud API and clear the stale VolumeAttachment so the new node can attach.

Why

Multi-Attach after a node failure is the canonical stateful-workload incident: block storage is single-attach, and a dead node may not release its attachment. The path is evidence (is the old attachment stale, is the node gone?), a targeted force-detach through the cloud once the controller's own six-minute timer has clearly failed, LB protection during recovery, and a detection mechanism afterwards.

The common mistake

Deleting the PVC to 'get a fresh one', or switching the class to ReadWriteMany. The first destroys the data; the second changes nothing about an existing block volume.

Read the docs

7 Quick recall

Multi-zone cluster: pods sit Pending with volume node affinity conflict because their disks were created in a zone with no room. Which StorageClass volumeBindingMode prevents that?

In short

WaitForFirstConsumer delays provisioning until a pod that uses the claim is scheduled.

Accepted

WaitForFirstConsumer · waitforfirstconsumer · wait for first consumer

Why

WaitForFirstConsumer lets the scheduler choose the node first so zonal volumes are created where the pod can run; Immediate provisions at claim time.

Next lesson Observability: metrics pipelines, kube-state-metrics, events, logging, and the alerts that matter
Drill · Storage
0:00

Loading…