Kubernetes Persistent Storage Explained: PV & PVC with Real-World Use Cases
In Kubernetes, Pods are ephemeral → if a Pod crashes or moves to another node, its local data is lost.
- PV + PVC solve this → by attaching persistent storage that survives Pod restarts, rescheduling, and even cluster upgrades.
- Think of it as:
- Pod = your app
- PVC = app’s request (“I need 20Gi storage”)
- PV = actual storage resource (EBS, Ceph, NFS, etc.)
PV & PVC — the idea in 6 bullets
- PersistentVolume (PV): A cluster resource that represents actual storage (EBS, GCE PD, Ceph, NFS, local SSD, etc.).
- PersistentVolumeClaim (PVC): An app’s request for storage (size, access mode, class). The control plane binds PVC → PV.
- StorageClass: Describes how to provision storage (type, parameters). With dynamic provisioning, a PV is created on demand.
- Mounting: Pods mount the PVC to a path (e.g.,
/data
). If the Pod restarts or is rescheduled, the data stays on the PV. - Access Modes:
ReadWriteOnce
(most common),ReadWriteMany
(shared across Pods),ReadOnlyMany
. - Backups & retention: Use snapshots/backup tools for PVs; deleting a PVC may or may not delete the underlying PV depending on the
reclaimPolicy
.
Real-time example
Order Service writes invoices to /data
.
- The Deployment mounts a PVC of 20Gi from the
gp3
StorageClass (AWS EBS). - A rollout causes Pods to restart on new nodes. The data persists because the PVC remains bound to the PV, which points to the same EBS volume.
- If the Pod crashes, Kubernetes restarts it; when it comes back, the same PVC is mounted and files are intact.
Minimal YAML (StorageClass → PVC → Pod/Deployment)
# 1) StorageClass (example: AWS EBS gp3). Use your cloud's provisioner.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: gp3
provisioner: ebs.csi.aws.com
parameters:
type: gp3
reclaimPolicy: Delete # or Retain (keeps the volume after PVC deletion)
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
---
# 2) PVC: app requests persistent storage
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: orders-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp3
resources:
requests:
storage: 20Gi
---
# 3) Deployment mounting the PVC at /data
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-service
spec:
replicas: 3
selector:
matchLabels:
app: order-service
template:
metadata:
labels:
app: order-service
spec:
containers:
- name: app
image: ghcr.io/example/order-service:1.0.0
ports:
- containerPort: 8080
volumeMounts:
- name: data
mountPath: /data
# optional: probes omitted for brevity
volumes:
- name: data
persistentVolumeClaim:
claimName: orders-pvc
Business Use Cases
1. Databases (High Priority Use Case)
- Example: MySQL, PostgreSQL, MongoDB, Cassandra
- Reason: Databases must store data persistently, otherwise every restart wipes records.
- PVC ensures DB data stays on disk volumes even if Pods die.
2. E-commerce Applications
- Example: Order Service writes invoices to
/data
. - Checkout microservice needs to save PDF invoices, receipts, or cart session data.
- With PVC → the data remains intact even when Pods autoscale up/down.
3. Content Management Systems (CMS)
- Example: WordPress, Drupal, Joomla running in Kubernetes.
- Media uploads (images, videos, docs) need persistent storage.
- Without PV/PVC, user-uploaded files would vanish after a Pod restart.
4. Data Science & AI/ML
- Example: Jupyter Notebooks, ML pipelines.
- Scientists save datasets, trained models, and checkpoints.
- PVC ensures large datasets survive across Pod lifecycles.
5. Logging & Monitoring Systems
- Example: Elasticsearch, Prometheus.
- Metrics & logs need to be retained for analysis.
- PVC ensures logs don’t disappear if Pods roll out.
#Kubernetes
#CloudComputing
#DevOps
#Containers
#CloudNative
#PersistentStorage
#Microservices
#CloudArchitecture