CFN Cloud
Cloud Future New Life
en zh
2025-10-09 · 64 views

Persistent Volumes and PVCs

Decouple storage providers and storage consumers.

A PV is a cluster-level storage resource, while a PVC is a claim made by the application. Kubernetes binds a PVC to a suitable PV.

Core ideas

  • PV: provided by admins or storage systems
  • PVC: declares storage needs
  • Binding: one PVC to one PV

Common flow

  1. Create a PVC
  2. Bind to a PV (dynamic or manual)
  3. Mount PVC into Pods

Tips

  • Prefer StorageClass for dynamic provisioning
  • Mind access modes: ReadWriteOnce vs ReadWriteMany

Practical notes

  • Start with a quick inventory: kubectl get nodes, kubectl get pods -A, and kubectl get events -A.
  • Compare desired vs. observed state; kubectl describe usually explains drift or failed controllers.
  • Keep names, labels, and selectors consistent so Services and controllers can find Pods.

Quick checklist

  • The resource matches the intent you described in YAML.
  • Namespaces, RBAC, and images are correct for the target environment.
  • Health checks and logs are in place before promotion.

Storage model and binding

Kubernetes separates storage intent from storage implementation. A PVC expresses what a workload needs, while a PV represents a piece of storage. StorageClass ties these together by describing how to provision volumes. PV and PVC usage is where you define how storage is created and how it will be attached to Pods.

Access modes and reclaim policy

Access modes describe how a volume can be mounted: read write once for single writer, read write many for shared access, or read only many for shared reads. Reclaim policy controls what happens when a claim is deleted. Delete removes the underlying volume, while Retain keeps it. Be intentional here because the policy determines whether data survives cleanup.

Expansion and snapshots

Many storage backends support volume expansion. When enabled, you can grow PVCs without recreating the workload, but you still need to confirm filesystem growth steps. Snapshots are a separate feature that enable backups or clones. Use them for testing upgrades and for faster recovery drills.

Performance and cost tradeoffs

Storage is often the bottleneck for stateful workloads. SSD backed classes provide low latency, while network attached storage can be more flexible but slower. Choose classes based on actual IOPS and throughput needs, not just size. Over provisioning is common, so track utilization and adjust requests to avoid paying for unused capacity.

Topology awareness

Some storage backends are zonal. The volume binding mode and scheduler need to align so Pods land in the same zone as their volumes. If you see pods stuck in Pending with volume binding errors, check topology constraints and StorageClass settings.

Data integrity and backup windows

Snapshots and backups should be taken at safe times. For databases, coordinate backup windows with application quiescing or use consistent snapshot tooling. Test restores regularly so you know the time to recover, not just the time to backup.

Operational workflow

Provision, mount, observe, and validate. Always verify that the PVC is bound before starting the workload. Monitor disk usage and inode pressure. For migrations, plan for data copy time and test your restore process. Storage is persistent, so cleaning up old PVCs and orphaned volumes should be part of your decommission process.

kubectl get pv
kubectl get pvc -n demo
kubectl describe pvc data-demo -n demo

Wrap-up: PVC Pending? don’t blame the Pod first

When storage gets weird, Pods usually look like the problem, but PVC/PV is where the root cause lives.

Start with:

  • Is the PVC bound?
  • Is there a StorageClass (and is it the right one)?
  • Any topology/zone constraints?

And don’t treat a PV as a backup. Backups need their own workflow.

References