0 / 15 lessons — 0%
Lesson 07 / 15
Volumes & persistent storage
Pods are disposable by design — restart one and its local filesystem is wiped clean. For anything that needs to survive that (a database, uploaded files), Kubernetes separates what storage you want from where it physically lives, through three objects working together.
| Object | Role |
|---|---|
| StorageClass | A "menu" of available storage types (fast SSD, slow HDD, cloud disk...) |
| PersistentVolume (PV) | An actual chunk of storage that's been provisioned |
| PersistentVolumeClaim (PVC) | A Pod's request — "I need 10GB, fast tier" — matched to a PV |
# pvc.yaml — a pod-facing request for storage apiVersion: v1 kind: PersistentVolumeClaim metadata: name: db-storage spec: accessModes: ["ReadWriteOnce"] storageClassName: standard resources: requests: storage: 10Gi
# mounting it into a pod spec: containers: - name: postgres image: postgres:16 volumeMounts: - mountPath: /var/lib/postgresql/data name: data volumes: - name: data persistentVolumeClaim: claimName: db-storage
Same idea as Docker volumes, one abstraction layer up: a PVC is basically "please give me a Docker-volume-like thing," and Kubernetes figures out which underlying disk actually satisfies it — often provisioning real cloud storage (an AWS EBS volume, an Azure Disk) on demand.
Try it yourselfAfter applying a PVC, run
kubectl get pvc and check its STATUS column — Bound means Kubernetes found or created a matching PersistentVolume for it.