Storage Overview¶
Container filesystems are ephemeral. For durable data, Kubernetes provides persistent storage primitives.
Ephemeral vs Persistent Storage¶
Ephemeral options:
emptyDir: temporary storage tied to pod lifetime.hostPath: host-node path mount (use sparingly, mainly for node-level agents).
Persistent options:
- PersistentVolume (PV)
- PersistentVolumeClaim (PVC)
- StorageClass
PV, PVC, and StorageClass¶
| Object | Purpose | Typical owner |
|---|---|---|
| PV | Actual storage resource | Platform automation or admin |
| PVC | Workload storage request | App team |
| StorageClass | Provisioning policy | Platform team |
The indirection exists for the same reason Services sit in front of pods: decoupling. The app team asks for "20Gi, single-writer" without knowing whether it comes from EBS, Ceph, or NFS. The platform team can change the backend without touching a single workload manifest.
How a volume reaches your pod¶
Dynamic provisioning is a chain of controllers, and each link is a distinct failure point:
sequenceDiagram
participant U as User
participant PVC as PVC (Pending)
participant CSI as CSI provisioner
participant S as Scheduler
participant K as kubelet
U->>PVC: create PVC (class: gp3-encrypted)
Note over PVC,S: WaitForFirstConsumer: nothing happens<br/>until a pod uses the PVC
U->>S: create pod referencing PVC
S->>S: pick node (zone-aware)
S->>CSI: trigger provisioning for that topology
CSI->>CSI: create backing volume, create PV
CSI->>PVC: bind PVC ↔ PV (1:1, exclusive)
K->>K: attach volume to node, mount into pod
A PVC and PV bind one-to-one and exclusively - once bound, the pairing holds until the PVC is deleted. When a PVC is deleted, the PV moves to Released and its reclaim policy decides what happens: Delete removes the backing volume; Retain keeps the PV (and data) but it will not rebind automatically - an admin must clean it and remove the old claimRef first. A Released PV that "won't bind" to a new PVC is expected behavior, not a bug.
PVC Example¶
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: standard
Access Modes¶
ReadWriteOnce(RWO): mounted read-write by one node at a time. Multiple pods on the same node can all mount it.ReadWriteOncePod(RWOP): mounted read-write by exactly one pod. Stricter than RWO. Added in Kubernetes 1.22 for single-writer guarantees at the pod level.ReadWriteMany(RWX): mounted read-write by many nodes simultaneously. Requires a compatible backend (NFS, CephFS, cloud file shares).ReadOnlyMany(ROX): mounted read-only by many nodes.
StorageClass Example (CSI)¶
Prefer CSI drivers and dynamic provisioning.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: gp3-encrypted
provisioner: ebs.csi.aws.com
parameters:
type: gp3
encrypted: "true"
allowVolumeExpansion: true
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
Note: provisioner is environment-specific. Use the CSI driver for your platform.
volumeBindingMode: WaitForFirstConsumer delays PV provisioning until a pod using the PVC is scheduled. This ensures the volume is created in the same availability zone as the pod. Use this mode for zonal storage backends (most cloud block storage). The default Immediate mode provisions the volume when the PVC is created, which can cause zone mismatches.
Volume expansion¶
allowVolumeExpansion: true in the StorageClass above is what makes a PVC growable - without it, editing a PVC's requested size is rejected. With it, you grow a volume by editing the claim:
What happens next is two-stage, and the distinction explains almost every "I resized it and nothing happened" report:
- Control-plane resize. The external-resizer sidecar calls the CSI driver's
ControllerExpandVolume, which grows the underlying block device (the EBS volume, the Azure disk, the Ceph RBD image). This part usually completes in seconds. - Node-side filesystem resize. The device is bigger, but the filesystem on it is not. The kubelet calls
NodeExpandVolumeon the node where the volume is attached, which runs the equivalent ofresize2fs/xfs_growfs. Only after this does the pod see more space.
Between the two stages the PVC carries a FileSystemResizePending condition:
kubectl get pvc db-data -o jsonpath='{.status.conditions}' | jq
kubectl get pvc db-data -o jsonpath='{.status.capacity.storage}' # actual, not requested
Watch status.capacity, not spec.resources.requests - the spec reflects what you asked for the moment you asked for it, and tells you nothing about whether the resize landed.
Two rules to internalize:
- Volumes cannot be shrunk. A smaller
requests.storageis rejected outright. If you over-provisioned, the path back is a new PVC and a data copy. - Online expansion is the norm now, but not universal. Modern CSI drivers expand a mounted volume without restarting the pod. Older drivers, and some filesystem/driver combinations, still require the pod to be restarted (offline expansion) before the node-side stage can run - a PVC parked in
FileSystemResizePendingwith no pod churn is the symptom.
VolumeAttributesClass¶
Expansion changes size. Changing performance - IOPS, throughput tier - on a live volume is what VolumeAttributesClass is for. It's a separate mutable class the PVC references:
apiVersion: storage.k8s.io/v1beta1
kind: VolumeAttributesClass
metadata:
name: gp3-high-iops
driverName: ebs.csi.aws.com
parameters:
iops: "12000"
throughput: "500"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-data
spec:
accessModes: [ReadWriteOnce]
storageClassName: gp3-encrypted
volumeAttributesClassName: gp3-high-iops
resources:
requests:
storage: 200Gi
Point the PVC at a different volumeAttributesClassName and the CSI driver modifies the volume in place - no new PVC, no data migration. Support is per-driver and the API has been moving through beta, so check both your Kubernetes version and your CSI driver before relying on it.
fsGroup on large volumes¶
When a pod sets securityContext.fsGroup, the kubelet by default walks the entire volume recursively and changes ownership and permissions on every file before the container starts. On a volume with millions of small files that is not a quick operation - it is a multi-minute pod-start stall that looks like a scheduling or image-pull problem and isn't.
OnRootMismatch checks the ownership of the volume's top-level directory first, and skips the recursive walk entirely if it already matches the expected fsGroup. Since the first mount sets it correctly, every subsequent pod start is effectively free. The default, Always, does the full walk every time. Set OnRootMismatch on any volume that holds a large file count - there is very little reason not to.
CSI attach limits as a scheduling constraint¶
Each node advertises how many CSI volumes it can have attached at once (node.status.allocatable carries an attachable-volumes-csi-<driver> entry), and the limit comes from the cloud provider and instance type - often in the range of 16 to 32 for block storage, and lower on small instance types than large ones.
The scheduler honors this, which means a node can be nowhere near its CPU or memory limits and still be unschedulable for a pod that needs a volume:
kubectl get csinode <node> -o yaml # per-driver allocatable count
kubectl describe node <node> | grep -i attach
The failure mode shows up in scheduling events as a node rejected for volume limits rather than resources, and it typically bites clusters running many small stateful pods on large nodes.
Reclaim Policy¶
Delete: deleting PVC removes backing storage.Retain: backing volume remains for manual recovery.
For critical stateful workloads, Retain can reduce accidental data loss risk.
Mounting a PVC in a Pod¶
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
volumes:
- name: app-storage
persistentVolumeClaim:
claimName: db-data
containers:
- name: app
image: nginx:1.27
volumeMounts:
- name: app-storage
mountPath: /data
Volume Snapshots¶
CSI-backed storage supports point-in-time volume snapshots via the VolumeSnapshot API (requires the external-snapshotter controller):
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: db-snapshot-2026-05-03
spec:
volumeSnapshotClassName: csi-snapclass
source:
persistentVolumeClaimName: db-data
Restore by creating a new PVC whose dataSource points at the snapshot. The restored volume is a new PV - the snapshot is not "rolled back" onto the original claim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-data-restored
spec:
storageClassName: gp3-encrypted
dataSource:
name: db-snapshot-2026-05-03
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi # must be >= the source volume's size
Then repoint the workload at db-data-restored (for a StatefulSet, that usually means deleting the pod's PVC and pre-creating a replacement under the name the volumeClaimTemplate expects). Snapshots are much faster than full backup/restore for large volumes and are useful for pre-upgrade checkpoints - but they typically live in the same storage backend and the same region as the source volume, so they are a rollback mechanism, not a disaster-recovery strategy. For cross-cluster and cross-provider restore, see Velero.
Operational Checks¶
If PVC remains Pending, validate storage class name, CSI driver health, and topology constraints (WaitForFirstConsumer PVCs stay Pending until a pod is scheduled).
Certification notes¶
- CKA storage tasks are usually: create a StorageClass/PV/PVC chain, mount it in a pod, and diagnose a
PendingPVC. Know thatPending+WaitForFirstConsumeris normal until a pod schedules. - Access modes are enforced at attach time, per node - RWO does not mean "one pod."
- Remember reclaim policy behavior for
RetainvsDelete; the released-PV-won't-rebind case appears in scenarios.
Key Takeaways¶
- A PersistentVolumeClaim is a request; a PersistentVolume is the actual storage. StorageClasses provision the second from the first.
- A
PendingPVC withWaitForFirstConsumeris not broken - binding is deliberately deferred until a pod schedules, so the volume lands in the right zone. - Access modes are enforced per node at attach time, so ReadWriteOnce does not mean "one pod."
- Reclaim policy decides what happens to data on delete:
Deleteremoves the backing volume,Retainkeeps it and leaves the PV unbindable until an admin intervenes. - StatefulSets build directly on this:
volumeClaimTemplatescreates one PVC per pod.
Further Reading¶
- Kubernetes: Persistent Volumes
- Kubernetes: expanding persistent volume claims
- Kubernetes: VolumeAttributesClass
- Kubernetes: configure a security context (
fsGroupChangePolicy) - Kubernetes: volume snapshots
- Kubernetes: storage capacity and CSI volume limits
Related Concepts¶
- StatefulSets
- Velero - backing up and restoring PV data across clusters, beyond in-place snapshots
- Resource Quotas and Limits
- Maintenance