PV, PVC, & StorageClasses

Difficulty: Intermediate

Question

Explain PersistentVolume (PV), PersistentVolumeClaim (PVC) and StorageClass. How does dynamic provisioning work?

Answer

A PersistentVolume (PV) is a piece of real storage in the cluster, such as an AWS EBS volume or an NFS share, represented as a cluster-wide API object. A PersistentVolumeClaim (PVC) is a namespaced request for storage ("I need 20Gi, ReadWriteOnce") that a Pod mounts. A StorageClass describes how to create PVs on demand, so when a PVC asks for that class, a CSI driver provisions a new volume and binds it automatically.

Why the split exists

The design separates two roles. Cluster admins (or the cloud) deal with the physical storage; application developers just ask for capacity and an access mode without knowing whether it is EBS gp3, a GCE Persistent Disk or Ceph. The Pod references the PVC, never the PV, so the same manifest works across clusters with different backends.

Static vs dynamic provisioning

  • Static: an admin creates PVs up front. A PVC binds to any available PV that satisfies its size, access mode and class.
  • Dynamic: the PVC names a storageClassName. The class's provisioner (for example ebs.csi.aws.com) creates a new volume, a PV object is created for it, and the PVC is bound. This is what almost every managed cluster uses today.

If a PVC omits storageClassName, the cluster's default StorageClass is used (marked with the annotation storageclass.kubernetes.io/is-default-class: "true").

Fields that come up in interviews

FieldValuesWhat it means
accessModesReadWriteOnce, ReadOnlyMany, ReadWriteMany, ReadWriteOncePodRWO is one node; RWOP (stable since 1.29) is one Pod; RWX needs shared storage like NFS or EFS
persistentVolumeReclaimPolicyDelete, RetainWhat happens to the disk when the PVC is deleted. Recycle is deprecated
volumeBindingModeImmediate, WaitForFirstConsumerWhen to provision. WaitForFirstConsumer waits until a Pod is scheduled so the disk is created in the same zone
allowVolumeExpansiontrue/falseWhether you can grow a PVC by editing its size

A PV moves through phases Available, Bound, Released and Failed.

Gotchas from real clusters

  • Zone mismatch: EBS volumes are zonal. With Immediate binding, the disk might be created in ap-south-1a while the Pod gets scheduled in 1b, leaving it stuck. Use WaitForFirstConsumer.
  • Accidental data loss: dynamically provisioned PVs default to Delete. Deleting the namespace deletes the PVC and the disk. For a payments database, use a class with reclaimPolicy: Retain and take snapshots.
  • RWX expectations: block storage like EBS cannot be mounted read-write on multiple nodes. If several replicas need a shared folder, use a file store (EFS, Filestore, Azure Files) or rethink the design.
  • StatefulSets use volumeClaimTemplates to create one PVC per replica (data-postgres-0, data-postgres-1). Scaling down does not delete those PVCs by default.
Dynamic provisioning flow. A PVC that names a StorageClass triggers the CSI driver to create and bind a new volume.
  1. Pod mounts PVC: The Pod spec only references the claim name.
  2. PVC requests 20Gi RWO: Names storageClassName: gp3.
  3. StorageClass gp3: Points to the ebs.csi.aws.com provisioner.
  4. CSI driver creates disk: A real EBS volume is created in the Pod's zone.
  5. PV bound to PVC: Kubernetes creates the PV object and binds it.

Code examples

StorageClass, PVC and Pod

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gp3-retain
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
reclaimPolicy: Retain               # keep the disk if the PVC is deleted
volumeBindingMode: WaitForFirstConsumer  # create disk in the Pod's zone
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: orders-db-data
spec:
  storageClassName: gp3-retain
  accessModes: [ReadWriteOnce]
  resources:
    requests:
      storage: 20Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: orders-db
spec:
  containers:
    - name: postgres
      image: postgres:16
      volumeMounts:
        - name: data
          mountPath: /var/lib/postgresql/data
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: orders-db-data

The Pod only knows the claim name. The StorageClass decides the disk type, where and when it is created, and whether it survives PVC deletion.

Inspecting storage objects

kubectl get storageclass          # (default) marks the default class
kubectl get pvc -n payments       # STATUS should be Bound
kubectl get pv                    # cluster-scoped, shows RECLAIM POLICY
kubectl describe pvc orders-db-data -n payments  # events explain Pending claims

A PVC stuck in Pending usually means no matching PV, no default class, or WaitForFirstConsumer waiting for a Pod.

Key points

  • PV is cluster-scoped real storage; PVC is a namespaced request; Pods reference PVCs.
  • StorageClass + CSI provisioner = dynamic provisioning, the default on managed clusters.
  • Dynamically provisioned volumes default to reclaimPolicy Delete; use Retain for critical data.
  • Use WaitForFirstConsumer for zonal disks to avoid zone mismatch.
  • ReadWriteOnce is per node, ReadWriteOncePod is per Pod, ReadWriteMany needs shared file storage.

Common follow-up questions

  • What happens to the data when you delete a PVC?
  • How do you resize a PVC that is running out of space?
  • Why might a PVC stay in Pending forever?
  • How do StatefulSets manage volumes per replica?
  • What is a CSI driver and why did Kubernetes move away from in-tree volume plugins?

Interview tips

  • Use the analogy: PV is the parking spot, PVC is the parking ticket, StorageClass is the valet who creates spots on demand.
  • Mention WaitForFirstConsumer and reclaim policy; they show production experience beyond definitions.
  • Be clear that RWO means one node, not one Pod.

Concepts covered

PersistentVolume, PersistentVolumeClaim, StorageClass, Dynamic Provisioning, Access Modes, Reclaim Policy

More Kubernetes & Orchestration questions