This article was translated using AI.
Kubernetes offers several storage abstractions—PV, PVC, StorageClass, plus whatever cloud disks you’re using (e.g., GCE Persistent Disk). It’s easy to get lost, so here’s a quick primer.
Why Not Just Use the Container Filesystem?
- Persistence: container filesystems are ephemeral. If a pod restarts unexpectedly, in-container data disappears.
- Sharing: multiple pods can’t easily share files stored inside a single container.
Volumes solve these problems by decoupling storage from pod lifecycles.
PersistentVolume (PV)
- A cluster-scoped resource representing a piece of storage.
- Exists independently of pods; multiple pods across nodes can mount the same PV.
- Can be pre-provisioned (static) or dynamically Provisioned via a StorageClass.
PersistentVolumeClaim (PVC)
- A user’s request for storage (“I need X GiB with ReadWriteOnce access”).
- Binds to a suitable PV. Without StorageClasses, binding is one-to-one (a PVC would “consume” the whole PV).
StorageClass
- Describes storage types (e.g., provisioner, parameters) and enables dynamic provisioning.
- PVCs referencing a StorageClass trigger Kubernetes to create the PV on demand (e.g., allocate a new GCE PD).
- Allows features like
allowVolumeExpansionfor resizing.
Volume Lifecycle
- Provisioning
- Static: admins create PVs up front.
- Dynamic: PVCs + StorageClass = Kubernetes allocates storage automatically.
- Binding: PVCs bind to matching PVs. If none exist, dynamic provisioning kicks in.
- Bound/Used: Pods mount the PVC. Kubernetes handles the plumbing.
- Reclaiming: When a PVC is deleted, the PV’s reclaim policy controls the outcome:
Retain: keep data (manual cleanup required).Delete: remove PV and underlying storage.Recycle: deprecated.
Cloud Disks
Public clouds provide the actual disks (AWS EBS, GCE PD, etc.). Kubernetes provisions PVs backed by those resources.
Common Patterns
Static provisioning:
Disk → PV → StorageClass → PVC → Pod
Dynamic provisioning (most managed clusters):
StorageClass → PVC → (Kubernetes auto-creates PV + Disk) → Pod
In short: StorageClass defines how to create storage, PVC requests it, and PV represents the actual disk. Understanding the flow keeps your stateful workloads reliable.***