CFN Cloud
Cloud Future New Life
en zh
2025-10-09 · 0 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.

Pods in a

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

Field checklist

When you move from a quick lab to real traffic, confirm the basics every time. Check resource requests, readiness behavior, log coverage, alerting, and clear rollback steps. A checklist prevents skipping the boring steps that keep services stable. Keep it short, repeatable, and stored with the repo so it evolves with the service and stays close to the code.

Troubleshooting flow

Start from symptoms, not guesses. Review recent events for scheduling, image, or probe failures, then scan logs for application errors. If traffic is failing, confirm readiness, verify endpoints, and trace the request path hop by hop. When data looks wrong, validate the active version and configuration against the release plan. Always record what you changed so a rollback is fast and a postmortem is accurate.

Small exercises to build confidence

Practice common operations in a safe environment. Scale the workload up and down and observe how quickly it stabilizes. Restart a single Pod and watch how the service routes around it. Change one configuration value and verify that the change is visible in logs or metrics. These small drills teach how the system behaves under real operations without waiting for an outage.

Production guardrails

Introduce limits gradually. Resource quotas, PodDisruptionBudgets, and network policies should be tested in staging before production. Keep backups and restore procedures documented, even for stateless services, because dependencies often are not stateless. Align monitoring with user outcomes so you catch regressions before they become incidents.

Documentation and ownership

Write down who owns the service, what success looks like, and which dashboards to use. Include the on-call rotation, escalation path, and basic runbooks for common failures. A small amount of documentation removes a lot of guesswork during incidents and helps new team members ramp up quickly.

Quick validation

After any change, validate the system the same way a user would. Hit the main endpoint, check latency, and watch for error spikes. Confirm that new pods are ready, old ones are gone, and metrics are stable. If the change touched storage, verify disk usage and cleanup behavior. If it touched networking, confirm DNS names and endpoint lists are correct.

Release notes

Write a short note with what changed, why it changed, and how to roll back. This is not bureaucracy; it prevents confusion during incidents. Even a few bullets help future you remember intent and context.

Capacity check

Compare current usage to requests and limits. If the service is close to limits, plan a small scaling adjustment before traffic grows. Capacity planning is easier when it is incremental rather than reactive.

Final reminder

Keep changes small and observable. If a release is risky, reduce scope and validate in staging first. Prefer frequent small updates over rare large ones. When in doubt, pick the option that simplifies rollback and reduces time to detect issues. The goal is not perfect config, but predictable operations.

References