After this lesson, you will be able to: Use PersistentVolumes, PersistentVolumeClaims, and StorageClasses to give Pods durable storage.
Containers are ephemeral. Stateful workloads (DBs, caches, uploads) need persistent storage. K8s abstracts that with PV / PVC / StorageClass.
StorageClass: a 'type' of storage available in the cluster. Examples: AWS gp3 SSD, GCP pd-balanced, NFS server. Cluster admin defines these. PersistentVolumeClaim (PVC): an APP's request, 'I want 10Gi of fast storage'. App writes this; cluster fulfills. PersistentVolume (PV): the actual storage that's been provisioned to fulfill a PVC. Usually auto-created by the StorageClass.
The canonical stateful-workload pattern.
apiVersion: v1kind: PersistentVolumeClaimmetadata:name: postgres-dataspec:accessModes: [ReadWriteOnce]storageClassName: standard # or gp3, pd-balanced, etc.resources:requests:storage: 20Gi---apiVersion: apps/v1kind: StatefulSet # not Deployment for stateful workloadsmetadata:name: postgresspec:serviceName: postgresreplicas: 1selector:matchLabels: { app: postgres }template:metadata: { labels: { app: postgres } }spec:containers:- name: postgresimage: postgres:16-alpineenv:- name: POSTGRES_PASSWORDvalueFrom:secretKeyRef: { name: postgres-secret, key: password }ports:- containerPort: 5432volumeMounts:- mountPath: /var/lib/postgresql/dataname: datavolumes:- name: datapersistentVolumeClaim:claimName: postgres-data
ReadWriteOnce (RWO): one node at a time can mount RW. The default; works for almost all single-instance DBs. ReadOnlyMany (ROX): many nodes mount RO. Used for shared static assets. ReadWriteMany (RWX): many nodes mount RW. Requires a shared filesystem (NFS, EFS, Azure Files). Rare in modern apps. RWO is the default; reach for the others only when you have a specific reason.
Deployment: Pods are interchangeable; identity doesn't matter. Don't use for databases. StatefulSet: Pods have stable, ordered identities (myapp-0, myapp-1, ...). Each has its own PVC. K8s scales them one at a time. Use for databases, distributed systems, queues. For most learners: stick with managed databases (RDS, Cloud SQL, Supabase) and avoid running stateful workloads in K8s unless you have a strong reason.
Running production databases in K8s without a backup strategy. Using Deployment for stateful workloads. Loses data on scale-down. Forgetting `storageClassName`. Defaults vary by cluster; explicit is safer. PVC that's too small. Many cloud providers DON'T support online expansion; you'll need to migrate data. Provision generously. Sharing a single PVC across many Pods with ReadWriteOnce. Only ONE Pod can mount it; others stay Pending.
Pick the honest answer.
Sign in and purchase access to unlock this lesson.