You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Containers are ephemeral — when a pod restarts, its filesystem is lost. Persistent storage decouples data from the container lifecycle. This lesson covers PersistentVolumes, PersistentVolumeClaims, StorageClasses, CSI drivers, and backup strategies.
┌──────────────────────────────────────┐
│ Pod │
│ ┌──────────────────────────────┐ │
│ │ Container │ │
│ │ volumeMount: /data │ │
│ └──────────────┬───────────────┘ │
└─────────────────┼────────────────────┘
│
┌─────────────────▼────────────────────┐
│ PersistentVolumeClaim (PVC) │
│ "I need 50Gi of fast SSD storage" │
└─────────────────┬────────────────────┘
│ binds to
┌─────────────────▼────────────────────┐
│ PersistentVolume (PV) │
│ "50Gi SSD volume, provisioned" │
└─────────────────┬────────────────────┘
│ backed by
┌─────────────────▼────────────────────┐
│ StorageClass │
│ "gp3-ssd" → CSI Driver → Cloud API │
└──────────────────────────────────────┘
A PV represents a piece of storage in the cluster, provisioned by an administrator or dynamically via a StorageClass.
apiVersion: v1
kind: PersistentVolume
metadata:
name: database-pv
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: fast-ssd
csi:
driver: ebs.csi.aws.com
volumeHandle: vol-0abc123def456789
A PVC is a request for storage by a user.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-data
spec:
accessModes:
- ReadWriteOnce
storageClassName: fast-ssd
resources:
requests:
storage: 50Gi
apiVersion: v1
kind: Pod
metadata:
name: postgres
spec:
containers:
- name: postgres
image: postgres:16
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
volumes:
- name: data
persistentVolumeClaim:
claimName: postgres-data
| Mode | Abbreviation | Description |
|---|---|---|
| ReadWriteOnce | RWO | Single node can mount read-write |
| ReadOnlyMany | ROX | Many nodes can mount read-only |
| ReadWriteMany | RWX | Many nodes can mount read-write |
| ReadWriteOncePod | RWOP | Single pod can mount read-write (K8s 1.27+) |
StorageClasses enable dynamic provisioning — PVs are created automatically when a PVC is submitted.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-ssd
provisioner: ebs.csi.aws.com
parameters:
type: gp3
iops: "5000"
throughput: "250"
encrypted: "true"
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
| Policy | Behaviour When PVC Is Deleted |
|---|---|
| Retain | PV and data are kept (manual cleanup) |
| Delete | PV and underlying storage are deleted |
| Recycle | Data is scrubbed, PV made available again |
Production tip: Use
Retainfor databases. You do not want accidental PVC deletion to destroy production data.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.