Stage 8, Part 1 of 9 · p. 65, Storage Deep Dive

PART 1: CORE THEORY

1. The Kubernetes Storage Model

Kubernetes storage is built on three core objects that separate what the application needs from how the infrastructure provides it.

The Three Core Objects

ObjectPurposeCreated By
PersistentVolume (PV)The actual storage resourceAdmin (static) or CSI driver (dynamic)
PersistentVolumeClaim (PVC)The application's request for storageApplication developer
StorageClassThe policy template for provisioningCluster admin

The Mental Model

Applications request storage through a PersistentVolumeClaim. The cluster satisfies that request through a PersistentVolume. A CSI driver is the integration layer that makes the underlying storage system usable from Kubernetes.

Why This Separation Matters

Without AbstractionWith Abstraction
App knows about EBS, GCP PD, NFSApp knows only about PVC
Changing storage = changing appChanging storage = changing StorageClass
No portabilityPortable across clusters
No access controlRBAC for storage

The Five Questions

When choosing storage, answer these five questions:

  1. Data path type: Block, file, or object-adjacent?
  2. Concurrent access: How many Pods need to read/write?
  3. Performance: What latency and throughput profile?
  4. Failure domain: Node, zone, or region?
  5. Operational controls: Snapshots, expansion, backup, retention?

2. CSI (Container Storage Interface)

CSI is the standard plugin model that Kubernetes uses to provision, attach, mount, resize, snapshot, and clone volumes.

What CSI Replaced

Before CSI, storage drivers were in-tree (compiled into Kubernetes). This meant:

CSI moves drivers out-of-tree. Vendors maintain their own drivers, and Kubernetes just talks to them via a standard gRPC interface.

The CSI Architecture

text
┌─────────────────────────────────────────────────────────────┐
│                    CSI ARCHITECTURE                         │
│                                                             │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  Kubernetes Control Plane                           │   │
│  │  ┌─────────────┐  ┌─────────────┐                  │   │
│  │  │ CSI         │  │ CSI         │                  │   │
│  │  │ Controller  │  │ Provisioner │                  │   │
│  │  │ (StatefulSet│  │ (external)  │                  │   │
│  │  └──────┬──────┘  └──────┬──────┘                  │   │
│  └─────────┼────────────────┼──────────────────────────┘   │
│            │                │                              │
│            ▼                ▼                              │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  CSI Driver (Deployed by vendor)                    │   │
│  │  ┌─────────────────────────────────────────────┐   │   │
│  │  │  Controller Plugin (StatefulSet)             │   │   │
│  │  │  • CreateVolume, DeleteVolume                │   │   │
│  │  │  • ControllerPublishVolume                   │   │   │
│  │  │  • CreateSnapshot, DeleteSnapshot            │   │   │
│  │  └────────────────────┬────────────────────────┘   │   │
│  │                       │                             │   │
│  │  ┌────────────────────▼────────────────────────┐   │   │
│  │  │  Node Plugin (DaemonSet)                     │   │   │
│  │  │  • NodeStageVolume, NodePublishVolume        │   │   │
│  │  │  • NodeUnpublishVolume                       │   │   │
│  │  └──────────────────────────────────────────────┘   │   │
│  └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘

Major CSI Drivers

DriverCloudStorage Type
ebs.csi.aws.comAWSBlock (EBS)
efs.csi.aws.comAWSFile (EFS)
pd.csi.storage.gke.ioGCPBlock (Persistent Disk)
filestore.csi.storage.gke.ioGCPFile (Filestore)
disk.csi.azure.comAzureBlock (Azure Disk)
file.csi.azure.comAzureFile (Azure Files)
cephfs.csi.ceph.comOn-premFile (CephFS)
rbd.csi.ceph.comOn-premBlock (Ceph RBD)
driver.longhorn.ioOn-premBlock (Longhorn)

2026 Recommendations:


3. PersistentVolumes (PV)

A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically by a StorageClass.

PV Lifecycle

PhaseMeaning
AvailableNot yet bound to a PVC
BoundBound to a PVC
ReleasedPVC deleted, PV not yet reclaimed
FailedAutomatic reclamation failed

Static PV Example

yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  hostPath:
    path: /mnt/data

Reclaim Policies

PolicyBehavior
RetainData preserved after PVC deletion; manual cleanup required
DeletePV and underlying storage deleted
RecycleDeprecated; basic scrub

Volume Modes

ModeBehavior
FilesystemMounted as a directory (default)
BlockRaw block device

4. PersistentVolumeClaims (PVC)

A PersistentVolumeClaim (PVC) is the application's request for storage. It specifies capacity, access mode, and optionally a StorageClass.

PVC Example

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-claim
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: fast-ssd

PVC Binding

The control plane watches for new PVCs and finds a matching PV (by capacity, access mode, StorageClass). If a PV is found, they are bound. If no PV matches but a StorageClass is specified, a new PV is dynamically provisioned.

PVC Status

StatusMeaning
PendingNot yet bound
BoundBound to a PV
LostPV no longer available

Using a PVC in a Pod

yaml
spec:
  containers:
  - name: app
    image: myapp:1.0
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: my-claim

PVC Retention

By default, PVCs are not deleted when a StatefulSet is deleted. This preserves data. To delete PVCs, you must do so manually or use a tool like Velero.


5. StorageClasses

A StorageClass is a policy template that defines how volumes are provisioned.

StorageClass Example

yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-ssd
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  iops: "3000"
  throughput: "125"
  encrypted: "true"
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

Key Parameters

ParameterPurpose
provisionerCSI driver to use
parametersDriver-specific settings (type, IOPS, encryption)
reclaimPolicyDelete or Retain
allowVolumeExpansionEnable online resize
volumeBindingModeImmediate or WaitForFirstConsumer

Volume Binding Modes

ModeBehavior
ImmediateProvision before Pod scheduling
WaitForFirstConsumerProvision after Pod scheduling (topology-aware)

Production recommendation: Use WaitForFirstConsumer for all storage classes. This ensures volumes are provisioned in the same zone as the Pod.

Default StorageClass

yaml
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"

The default StorageClass is used when a PVC doesn't specify storageClassName.

2026 StorageClass Best Practices

PracticeWhy
Use WaitForFirstConsumerTopology-aware provisioning
Enable allowVolumeExpansionOnline resize
Set reclaimPolicy: RetainData safety for critical workloads
Multiple classesDifferent performance tiers
Mount optionsPerformance tuning (rsize, wsize, nconnect)

6. Access Modes

Access modes define how many nodes can mount a volume and whether they can write.

The Four Access Modes

ModeAbbreviationMeaning
ReadWriteOnceRWOMounted read-write by a single node
ReadOnlyManyROXMounted read-only by many nodes
ReadWriteManyRWXMounted read-write by many nodes
ReadWriteOncePodRWOPMounted read-write by a single Pod

Access Mode by Storage Type

Storage TypeRWOROXRWXRWOP
Block (EBS, PD, Azure Disk)✅❌❌✅
File (EFS, Filestore, Azure Files)✅✅✅✅
Ceph RBD✅✅❌✅
CephFS✅✅✅✅
Longhorn✅❌✅✅
Local PV✅❌❌✅

When to Use Each

Use CaseAccess Mode
Database (PostgreSQL, MySQL)RWO
Message queue (Kafka)RWO
Shared CMS mediaRWX
Read-only configROX
Single Pod with strict isolationRWOP

RWOP (ReadWriteOncePod)

Introduced in Kubernetes 1.22, GA in 1.29. RWOP ensures only one Pod can mount the volume read-write. This is stricter than RWO (which allows multiple Pods on the same node).

yaml
spec:
  accessModes:
  - ReadWriteOncePod

1:1 copy of the class Google Doc, code in code blocks.