TL;DR
A comprehensive guide to Kubernetes storage options, including volumes, persistent volumes, storage classes, and best practices for data management.
Kubernetes Storage Guide: From Volumes to Storage Classes
Executive Summary
Kubernetes storage looks simple — a pod asks for a volume, a claim binds, data persists — until the first reclaim policy deletes something irreplaceable or a database pod is rescheduled onto the wrong side of a region. This guide covers the full model: volume types and their lifetimes, PersistentVolumes and claims, StorageClasses and dynamic provisioning, snapshots, StatefulSet storage, and cloud CSI drivers. By the end you will be able to choose the right storage shape per workload, set reclaim and binding policies deliberately, and protect data with snapshots that are actually restorable.
Why This Matters
Compute in Kubernetes is disposable by design; data is not. Every storage mistake is asymmetric — a misconfigured reclaim policy or an untested backup is invisible for months and then total. Storage choices also quietly decide your availability: a ReadWriteOnce volume pins a pod to one node, a zonal disk pins it to one zone, and a StatefulSet scaled carelessly can strand claims in a zone the workload has left. Getting storage right is what lets the rest of the platform's disposability be a feature instead of a threat.
Core Concepts
Volume Types and Their Lifetimes
A volume's lifetime defines what it is safe to hold:
| Volume type | Use case | Persistence |
|---|---|---|
| emptyDir | Temporary storage, scratch space, shared pod cache | Pod lifetime |
| hostPath | Node-level agents that must read the host filesystem | Node lifetime |
| PersistentVolume | Durable application data | Independent of pods |
| ConfigMap | Configuration data | Cluster config |
| Secret | Sensitive data | Cluster config |
The simplest form, a scratch volume shared between containers in a pod:
apiVersion: v1
kind: Pod
metadata:
name: volume-example
spec:
containers:
- name: app
image: nginx
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
emptyDir: {}Treat hostPath as a security decision, not a convenience: it hands a container the node's filesystem, and belongs almost exclusively to system DaemonSets.
PersistentVolumes and Claims: The Contract
The PV/PVC split separates who provides storage from who consumes it. A PersistentVolume is a cluster resource describing real storage; a PersistentVolumeClaim is a pod's request for capacity and access mode. The binder matches them:
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
storageClassName: standard
hostPath:
path: /data/example-pv
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: standardAccess modes carry architectural weight. ReadWriteOnce means one node at a time — fine for a database, fatal for a workload you expect to roll freely across nodes. ReadWriteMany requires a backend that supports it (NFS, CephFS, cloud file services) and is usually slower. Choose the mode from the workload's real sharing pattern, not from habit.
StorageClasses: Policy, Not Just Provisioning
A StorageClass names a provisioner (a CSI driver) plus the parameters and policies every claim in that class inherits:
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: fast provisioner: kubernetes.io/aws-ebs parameters: type: gp2 fsType: ext4 reclaimPolicy: Delete allowVolumeExpansion: true volumeBindingMode: WaitForFirstConsumer
Three fields deserve deliberate thought. reclaimPolicy decides what happens when a claim is deleted: Delete destroys the underlying volume (right for ephemeral environments, dangerous for data), Retain leaves it for manual recovery. volumeBindingMode: WaitForFirstConsumer delays provisioning until a pod is scheduled, so the volume is created in the same zone as the pod — skipping this is a classic cause of unschedulable pods in multi-zone clusters. allowVolumeExpansion lets claims grow later, which is the difference between a resize and a migration.
Snapshots: Backup That Lives Next to the Data
VolumeSnapshots capture a point-in-time copy of a claim through the CSI driver:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: data-snapshot
spec:
volumeSnapshotClassName: csi-hostpath-snapclass
source:
persistentVolumeClaimName: example-pvcSnapshots are the fast, local layer of data protection — quick restores, pre-upgrade checkpoints. They are not a complete backup strategy: they typically live in the same failure domain as the source, and restoring one is a procedure you must rehearse, not a hope. Pair them with off-cluster backups for anything you cannot recreate.
StatefulSets: One Claim per Replica
StatefulSets give each replica a stable identity and its own claim via volumeClaimTemplates — pod web-0 always reattaches to the same volume after rescheduling:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1GiKnow the trap: scaling a StatefulSet down does not delete the claims, and deleting the StatefulSet does not either. That is protective by design — and a recurring source of orphaned volumes and surprise storage bills if nobody owns cleanup.
Cloud CSI Drivers
On managed clouds the provisioner is the provider's CSI driver, and the StorageClass is where provider features are switched on — encryption at rest being the one to never skip:
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: ebs-sc provisioner: ebs.csi.aws.com parameters: type: gp3 encrypted: "true" kmsKeyId: arn:aws:kms:us-west-2:111122223333:key/1234abcd
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: azure-disk provisioner: disk.csi.azure.com parameters: skuName: Premium_LRS kind: Managed fsType: ext4
Monitoring Storage
Watch capacity before it is an outage: alert on claim utilisation trending toward full and on volumes approaching inode exhaustion, which arrives silently on small filesystems. Export the storage layer's metrics like any other:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: storage-metrics
spec:
selector:
matchLabels:
k8s-app: storage-provisioner
endpoints:
- port: metrics
interval: 30sDecision Framework
| Situation | Recommendation |
|---|---|
| Scratch space, caches, pod-local working files | emptyDir — sized with a memory/disk limit |
| Single-writer database or stateful service | StatefulSet + ReadWriteOnce claim on the fastest block class |
| Shared content read by many pods | ReadWriteMany file storage (NFS/EFS/Filestore class), accepting lower performance |
| Irreplaceable data | reclaimPolicy Retain + snapshots + off-cluster backups |
| Throwaway dev/test environments | reclaimPolicy Delete, cheaper storage class |
| Multi-zone cluster | WaitForFirstConsumer binding on every class, no exceptions |
Implementation Checklist
Trade-offs
Networked block storage is durable and portable across rescheduling within a zone, but its latency is never local-disk latency, and zone pinning constrains the scheduler. Local volumes are fast and fragile in equal measure — the node is the failure domain. ReadWriteMany file storage simplifies sharing while capping throughput and adding a network dependency to every read. There is no universally correct backend; there is only the workload's actual access pattern, durability requirement, and failure tolerance, priced honestly.
When Not to Use
Conclusion
Kubernetes storage is a set of explicit contracts: lifetime, access mode, reclaim behaviour, and failure domain. Read those four fields on every claim and class you ship, rehearse your restores, and the platform's disposability stops being a threat to the data it carries.
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.