Storage: PVs and PVCs
Key Takeaways for AI & Readers
- Persistence Strategy: PVs and PVCs separate the physical storage (PV) from the user's request for storage (PVC), ensuring data survives container restarts.
- The Binding Handshake: A PVC "binds" to a PV only if the PV meets the requested capacity and access mode requirements.
- Dynamic Provisioning: StorageClasses automate PV creation, eliminating the need for administrators to manually pre-provision physical disks.
- Access Modes: Understanding
ReadWriteOnce(single node) vs.ReadWriteMany(shared across nodes) is critical for architectural planning.
Containers are ephemeral. When they die, their data dies with them. To save data permanently (like a database), Kubernetes uses PersistentVolumes (PV) and PersistentVolumeClaims (PVC).
The Handshake Visualizer
- PV: A piece of storage in the cluster (Administrator created).
- PVC: A request for storage (User created).
Try requesting storage below. Notice that a Claim will only Bind to a Volume if the Volume is big enough and available.
Create PersistentVolumeClaim (PVC)
Active Claims (Click to Delete)
No active PVCs
> Cluster initialized with 2 PersistentVolumes.
Key Concepts
- PersistentVolume (PV): A resource in the cluster (like a node) that is a volume plugin like EBS, NFS, or local disk.
- PersistentVolumeClaim (PVC): A request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources.
- StorageClass: A "template" that allows PVs to be dynamically provisioned when a PVC is created (so you don't have to manually create PVs).
3. Storage Types: Block vs. File
When choosing a StorageClass, you must understand the underlying technology:
Block Storage (ReadWriteOnce)
- Examples: AWS EBS, Azure Disk, GCE Persistent Disk.
- Performance: High performance, low latency.
- Limitation: Usually can only be attached to one Node at a time. If your pod moves to a different node, the disk must be detached and re-attached (takes ~30s).
File Storage (ReadWriteMany)
- Examples: NFS, AWS EFS, Azure Files.
- Performance: Slightly higher latency.
- Benefit: Can be shared by many Pods on many Nodes simultaneously. Perfect for shared assets or log storage.
4. Binding Rules
- Capacity: The PV must have at least as much storage as the PVC requested.
- Access Modes: Must match (e.g., ReadWriteOnce).
- Status: The PV must be
Available.