Opscraft
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 diagramPodmounts the claimPVC20Gi,ReadWriteOnceStorageClassgp3ebs.csi.aws.comPVa real EBS volume
Figure 1. Dynamic provisioning: a pod asks for storage with a PVC; the StorageClass tells the CSI driver how to create a real disk.
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: Delete removes the backing volume when the PVC is deleted; Retain keeps it for manual recovery — use for important data.
  • WaitForFirstConsumer delays provisioning until a pod is scheduled, so the volume is created in the same AZ as the pod. With Immediate, 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 diagramImmediateWaitForFirstConsumerVolume created in AZ-a straight awayPod scheduled to AZ-bStuck: volume node affinity conflictWaits until the pod is scheduledCreates the volume in that AZThe default to use for EBS
Figure 2. EBS volumes live in one AZ. WaitForFirstConsumer creates the volume where the pod lands, avoiding a pod and disk in different zones.
Swipe sideways to see all of it, or tap to open it full screen.