KubernetesIntermediate

Kubernetes Storage Guide: From Volumes to Storage Classes

7 min read

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 typeUse casePersistence
emptyDirTemporary storage, scratch space, shared pod cachePod lifetime
hostPathNode-level agents that must read the host filesystemNode lifetime
PersistentVolumeDurable application dataIndependent of pods
ConfigMapConfiguration dataCluster config
SecretSensitive dataCluster 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: standard

Access 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-pvc

Snapshots 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: 1Gi

Know 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: 30s

Decision Framework

SituationRecommendation
Scratch space, caches, pod-local working filesemptyDir — sized with a memory/disk limit
Single-writer database or stateful serviceStatefulSet + ReadWriteOnce claim on the fastest block class
Shared content read by many podsReadWriteMany file storage (NFS/EFS/Filestore class), accepting lower performance
Irreplaceable datareclaimPolicy Retain + snapshots + off-cluster backups
Throwaway dev/test environmentsreclaimPolicy Delete, cheaper storage class
Multi-zone clusterWaitForFirstConsumer binding on every class, no exceptions

Implementation Checklist

  • [ ] Every production StorageClass reviewed for reclaimPolicy — Retain anywhere data is irreplaceable
  • [ ] WaitForFirstConsumer set on classes used in multi-zone clusters
  • [ ] Volume expansion enabled on classes backing growing workloads
  • [ ] Encryption at rest enabled in cloud StorageClass parameters
  • [ ] Snapshot schedule running for stateful claims, and one restore actually rehearsed
  • [ ] Off-cluster backup exists for data that cannot be recreated
  • [ ] Alerts on claim capacity and inode utilisation before they reach critical
  • [ ] Orphaned-claim cleanup owned: someone lists unbound/retained volumes on a schedule
  • [ ] hostPath usage inventoried and limited to system DaemonSets
  • 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

  • PersistentVolumes for data a managed service should own: if a managed database (RDS, Cloud SQL, Azure Database) fits, use it — running stateful databases on cluster storage means you own backup, failover, and upgrade correctness.
  • emptyDir for anything you would miss: it is deleted with the pod, including on a routine reschedule. Caches and rebuildable scratch only.
  • ReadWriteMany by default: sharing modes are a performance and complexity commitment. If each pod can own its data, ReadWriteOnce with a StatefulSet is simpler and faster.
  • 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.

    Share this articleShare on XShare on LinkedIn

    Keep the decision frameworks coming

    One practical architecture guide a week — patterns, trade-offs, and when not to use them. No spam, unsubscribe anytime.