Containers are ephemeral. When a pod restarts, its filesystem resets. Persistent storage lets data survive pod restarts, rescheduling, and even node failures.
Core Concepts
StorageClass → defines HOW storage is provisioned
↓
PersistentVolume (PV) → actual storage resource
↓
PersistentVolumeClaim (PVC) → request for storage by a pod
↓
Pod → mounts the PVC as a volumeStorageClass
Defines the storage backend and provisioning behavior:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-ssd
provisioner: ebs.csi.aws.com
parameters:
type: gp3
iops: "3000"
throughput: "125"
encrypted: "true"
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
allowVolumeExpansion: true| Field | Purpose |
|---|---|
provisioner | CSI driver or built-in provisioner |
volumeBindingMode | Immediate or WaitForFirstConsumer |
reclaimPolicy | Delete (default) or Retain |
allowVolumeExpansion | Can PVCs be resized? |
Dynamic Provisioning (Recommended)
Just create a PVC — the StorageClass automatically creates the PV:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
spec:
accessModes:
- ReadWriteOnce
storageClassName: fast-ssd
resources:
requests:
storage: 20GiUse in a pod:
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
template:
spec:
containers:
- name: app
image: my-app
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: app-dataMaster this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →Static Provisioning
For pre-existing storage (NFS, existing EBS volumes):
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-data
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: nfs.internal
path: /exports/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: shared-data
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
volumeName: nfs-data # Bind to specific PVAccess 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 (K8s 1.27+) |
Cloud block storage (EBS, Azure Disk) only supports RWO. For RWX, use NFS, EFS, or CephFS.
StatefulSets
For databases and stateful applications — each pod gets its own PVC:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
serviceName: postgres
replicas: 3
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:16-alpine
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
env:
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: fast-ssd
resources:
requests:
storage: 50GiThis creates:
- data-postgres-0 → 50Gi PVC for pod 0
- data-postgres-1 → 50Gi PVC for pod 1
- data-postgres-2 → 50Gi PVC for pod 2
PVCs persist even if pods are deleted.
Get weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Volume Expansion
# Edit the PVC
kubectl patch pvc app-data -p '{"spec":{"resources":{"requests":{"storage":"50Gi"}}}}'
# Check status
kubectl get pvc app-dataRequires allowVolumeExpansion: true on the StorageClass. Some CSI drivers need a pod restart.
Volume Snapshots
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: db-backup-20260204
spec:
volumeSnapshotClassName: csi-snapclass
source:
persistentVolumeClaimName: data-postgres-0Restore from snapshot:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-restore
spec:
accessModes:
- ReadWriteOnce
storageClassName: fast-ssd
resources:
requests:
storage: 50Gi
dataSource:
name: db-backup-20260204
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.ioTroubleshooting
# PVC stuck in Pending
kubectl describe pvc my-pvc
# Common causes: no StorageClass, no capacity, wrong access mode
# Check PV status
kubectl get pv
# Check CSI driver
kubectl get csidrivers
kubectl get pods -n kube-system | grep csi| Issue | Cause | Fix |
|---|---|---|
| PVC Pending | No matching StorageClass | Create StorageClass or set default |
| PVC Pending | Volume binding mode | Pod must be scheduled first (WaitForFirstConsumer) |
| Permission denied | Wrong fsGroup | Set securityContext.fsGroup |
| Data lost on restart | Using emptyDir, not PVC | Switch to PVC |
| Cannot mount RWX | Block storage limitation | Use NFS/EFS for shared storage |
What's Next?
Our MLflow for Kubernetes MLOps course covers persistent storage for ML model artifacts and training data. Docker Fundamentals teaches volume management. First lessons are free. -e ---
Ready to go deeper? Explore our hands-on DevOps courses — from Docker and Terraform to MLflow on Kubernetes.
Ready to learn by doing?
Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.
Related Articles
Docker Volumes and Persistent Data
Manage persistent data in Docker with named volumes and bind mounts. Backup strategies, restore procedures, and container data sharing.
Kubernetes Services and Ingress
Expose Kubernetes workloads with ClusterIP, NodePort, LoadBalancer services and Ingress controllers. Practical examples.
kubectl Cheat Sheet for DevOps
Essential kubectl commands for pods, deployments, services, logs, and debugging Kubernetes clusters. Copy-paste ready DevOps reference.
Kubernetes Troubleshooting Checklist
Kubernetes troubleshooting checklist. Pod failures, CrashLoopBackOff, networking issues, DNS resolution, and storage fixes.
Kubescape Kubernetes Security Scan
Kubescape scans Kubernetes clusters against NSA, MITRE, and CIS benchmarks. Learn how to audit cluster security, fix misconfigurations, and integrate.
Kubevirt VMs on Kubernetes Guide
KubeVirt runs virtual machines alongside containers on Kubernetes. Learn how to deploy VMs as pods, migrate legacy workloads, and manage hybrid container-VM.
Explore topics
Browse more articles on the topics covered here.