DEV Community

InstaDevOps
InstaDevOps

Posted on • Originally published at instadevops.com

Kubernetes Persistent Storage: PVs, CSI Drivers & StatefulSets

Kubernetes Storage: PVs, PVCs, StorageClasses, and CSI Drivers Explained

Kubernetes was designed for stateless workloads, and it shows. Running databases, message queues, or any stateful application on Kubernetes requires understanding the storage abstraction layer - PersistentVolumes, PersistentVolumeClaims, StorageClasses, and CSI drivers - which confuses even experienced engineers. The concepts are not complicated individually, but the way they interact creates a system that is easy to misconfigure.

A PersistentVolume (PV) represents a piece of storage in the cluster. A PersistentVolumeClaim (PVC) is a request for storage by a pod. A StorageClass defines how storage is dynamically provisioned - which CSI driver to use, what type of disk (gp3, io2, sc1 on AWS), and reclaim policy (delete or retain). In practice, you define StorageClasses once per cluster, and developers create PVCs in their deployments. Dynamic provisioning handles the rest: when a PVC is created, the StorageClass triggers the CSI driver to provision the actual cloud volume and create the PV automatically.

The critical decisions are access modes and reclaim policies. ReadWriteOnce (RWO) volumes can only be mounted by one node - fine for databases but problematic for deployments that scale across nodes. ReadWriteMany (RWX) requires a shared filesystem like EFS or NFS. Reclaim policy should be Retain for any data you care about - Delete means the volume is destroyed when the PVC is deleted, which has caused data loss for many teams. For production databases on Kubernetes, use StatefulSets with volumeClaimTemplates, configure volume snapshots for backups, and test your restore procedure regularly.


Running stateful workloads on Kubernetes? InstaDevOps helps teams configure reliable storage for production Kubernetes clusters. Book a free consultation.

Top comments (0)