Kubernetes in depth · Lesson 6 of 11 · 3 min read
Storage
Volume types
| Volume | Lifetime / use |
|---|---|
emptyDir |
Created with the pod, deleted with it; scratch space or sharing files between containers (medium: Memory for tmpfs) |
configMap, secret, projected, downwardAPI |
Inject config, secrets, ServiceAccount tokens, pod metadata as files |
hostPath |
A node directory — powerful and dangerous (node access); for system agents only |
persistentVolumeClaim |
Durable storage via the PV subsystem |
ephemeral |
Per-pod PVC created and deleted with the pod (generic ephemeral volumes) |
PV, PVC and StorageClass
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
- PersistentVolume (PV) — a piece of storage (an EBS volume, EFS access point), cluster-scoped.
- PersistentVolumeClaim (PVC) — a namespaced request for storage (size, access mode, class). Pods mount PVCs.
- StorageClass — how to dynamically provision PVs: provisioner (CSI driver), parameters, reclaim policy, binding mode.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata: { name: gp3 }
provisioner: ebs.csi.aws.com
parameters: { type: gp3, encrypted: "true" }
reclaimPolicy: Delete # or Retain
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
- Access modes:
ReadWriteOnce(one node — EBS),ReadOnlyMany,ReadWriteMany(many nodes — EFS/NFS),ReadWriteOncePod(one pod). - Reclaim policy:
Deleteremoves the backing volume when the PVC is deleted;Retainkeeps it for manual recovery — use for important data. WaitForFirstConsumerdelays provisioning until a pod is scheduled, so the volume is created in the same AZ as the pod. WithImmediate, an EBS volume can land in AZ-a while the pod is scheduled to AZ-b → stuck.- EBS volumes are zonal: a pod with an EBS PVC can only run in that AZ; if that AZ's nodes are full, the pod is Pending ("volume node affinity conflict").
- CSI (Container Storage Interface) drivers — EBS CSI, EFS CSI, FSx — implement provisioning, attach/mount, expansion and VolumeSnapshots.
- Expansion: edit the PVC's size (if
allowVolumeExpansion); the CSI driver grows the volume and the filesystem.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.