Kubernetes Persistent Volumes Guide
Manage Kubernetes Persistent Volumes with PV, PVC, and StorageClass. Dynamic provisioning, access modes, reclaim policies, and volume expansion.
π‘ Quick Answer: PersistentVolume (PV) is the storage, PersistentVolumeClaim (PVC) is the request, StorageClass enables dynamic provisioning. Create a StorageClass, reference it in a PVC, mount the PVC in a pod. Use
ReadWriteOncefor single-node (block),ReadWriteManyfor shared (NFS/CephFS), andallowVolumeExpansion: trueon StorageClass for online resize.
The Problem
Container storage is ephemeral β when a pod restarts, all data is lost. Applications need:
- Data persistence across pod restarts
- Shared storage between pods
- Storage provisioned on demand
- Volume resizing without downtime
- Different storage tiers (SSD, HDD, NFS)
The Solution
StorageClass (Dynamic Provisioning)
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-ssd
provisioner: kubernetes.io/aws-ebs # Or csi driver
parameters:
type: gp3
iops: "3000"
throughput: "125"
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumerPersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
namespace: production
spec:
accessModes:
- ReadWriteOnce
storageClassName: fast-ssd
resources:
requests:
storage: 20GiMount in Pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
template:
spec:
containers:
- name: app
image: myapp:v1
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: app-dataStatic PersistentVolume (Pre-Provisioned)
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-share
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: nfs.example.com
path: /exports/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: shared-data
spec:
accessModes:
- ReadWriteMany
storageClassName: "" # Empty = static binding
resources:
requests:
storage: 100GiAccess Modes
| Mode | Abbreviation | Description |
|---|---|---|
ReadWriteOnce | RWO | Single node read-write |
ReadOnlyMany | ROX | Multiple nodes read-only |
ReadWriteMany | RWX | Multiple nodes read-write |
ReadWriteOncePod | RWOP | Single pod read-write (v1.27+) |
Reclaim Policies
| Policy | Behavior |
|---|---|
Delete | PV deleted when PVC is deleted (dynamic default) |
Retain | PV preserved, must be manually reclaimed |
Recycle | Deprecated β use Delete or Retain |
Volume Expansion
# Edit PVC to request more storage
kubectl patch pvc app-data -p '{"spec":{"resources":{"requests":{"storage":"50Gi"}}}}'
# StorageClass must have allowVolumeExpansion: true
# For filesystem volumes, pod restart may be needed for resize to take effectgraph LR
SC[StorageClass<br/>fast-ssd] --> |provisions| PV[PersistentVolume<br/>20Gi gp3]
PVC[PersistentVolumeClaim<br/>20Gi RWO] --> |binds to| PV
POD[Pod] --> |mounts| PVC
style SC fill:#2196F3,color:white
style PV fill:#4CAF50,color:white
style PVC fill:#FF9800,color:whiteCommon Issues
PVC stuck in Pending
No matching PV or StorageClass provisioner failing. Check kubectl describe pvc <name> for events. With WaitForFirstConsumer, PVC stays Pending until a pod uses it.
Volume not expanding
StorageClass must have allowVolumeExpansion: true. Some CSI drivers require pod restart for filesystem resize.
Data lost after PVC delete
ReclaimPolicy was Delete. Use Retain for important data and always back up with Velero.
Best Practices
- Use dynamic provisioning β let StorageClass handle PV creation
WaitForFirstConsumerβ ensures PV is in the same zone as the podRetainfor production data β prevents accidental deletion- Enable volume expansion β resize without redeployment
- RWO for databases, RWX for shared content β match access mode to use case
- Always back up PVs β storage is not backup
Key Takeaways
- PV = storage, PVC = request, StorageClass = dynamic provisioning template
- Dynamic provisioning creates PVs automatically when PVCs are created
WaitForFirstConsumerensures zone-aware volume placement- Volume expansion works online for most CSI drivers
- Use
Retainreclaim policy for data you canβt afford to lose ReadWriteOncePod(v1.27+) provides the strongest single-writer guarantee

Recommended
Kubernetes Recipes β The Complete Book100+ production-ready patterns with detailed explanations, best practices, and copy-paste YAML. Everything in one place.
Get the Book βLearn by Doing
CopyPasteLearn β Hands-on Cloud & DevOps CoursesMaster Kubernetes, Ansible, Terraform, and MLOps with interactive, copy-paste-run lessons. Start free.
Browse Courses βπ Deepen Your Skills β Hands-on Courses
Courses by CopyPasteLearn.com β Learn IT by Doing
