Stage 5 · Platform
Stateful Storage Operations
PV & PVC Lifecycle
Binding, reclaim policies, access modes, volume expansion, and finalizer behavior.
PV and PVC Overview
PersistentVolumes (PV) represent storage resources. PersistentVolumeClaims (PVC) are requests for storage. PVs are cluster-scoped; PVCs are namespace-scoped. PVCs bind to PVs based on capacity, access modes, and storage class.
| Resource | Scope | Purpose |
|---|---|---|
| PV | Cluster | Represents physical storage |
| PVC | Namespace | Request for storage by a pod |
| StorageClass | Cluster | Defines storage provisioner and parameters |
Binding Process
When a PVC is created, Kubernetes looks for a PV that satisfies the claim: sufficient capacity, matching access modes, and matching StorageClass. If found, the PV and PVC are bound. If not, the PVC stays Pending until a suitable PV appears.
apiVersion: v1
kind: PersistentVolume
metadata:
name: manual-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: manual
hostPath:
path: /mnt/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: manualThe PVC requests 5Gi. The PV has 10Gi. They bind because the PV has enough capacity. The access modes must match. The StorageClass must match (or both must be empty string).
Reclaim Policies
ReclaimPolicy determines what happens to the PV when the PVC is deleted. Delete removes the volume from storage. Retain keeps the volume but disconnects it. Recycle (deprecated) clears the volume for reuse.
Delete:
PVC deleted -> PV deleted -> Volume deleted from storage
(Data lost — use only for ephemeral data)
Retain:
PVC deleted -> PV released -> Manual intervention required
(Data preserved — admin must reattach or delete)
Recycle (deprecated):
PVC deleted -> Volume cleared (rm -rf /thevolume/*)
PV available for new claimsRetain is the safest policy. The PV enters Released state after the PVC is deleted. An admin must manually back up data, reattach the PV to a new PVC, or delete the PV. Delete is only safe for disposable data.
Access Modes
Access modes define how a volume can be mounted. ReadWriteOnce (RWO) allows single-node read/write. ReadOnlyMany (ROX) allows multi-node read-only. ReadWriteMany (RWX) allows multi-node read/write. ReadWriteOncePod (RWOP) allows single-pod read/write.
| Mode | Abbreviation | Support |
|---|---|---|
| ReadWriteOnce | RWO | Most block storage (EBS, PD, Azure Disk) |
| ReadOnlyMany | ROX | NFS, CephFS, object storage |
| ReadWriteMany | RWX | NFS, CephFS, Azure Files |
| ReadWriteOncePod | RWOP | CSI drivers with RWOP support |
Volume Expansion
Volume expansion grows a PVC without deleting it. The StorageClass must allow expansion (allowVolumeExpansion: true). Expansion works online (while mounted) or offline (while detached) depending on the CSI driver.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: expanding-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: expandable
resources:
requests:
storage: 100Gi # Changed from 50GiUpdate the storage request to the new size. Kubernetes calls the CSI driver to expand the volume. Online expansion happens while the volume is mounted. The PVC status shows Resizing, then Bound when complete.
Finalizer Behavior
PVs and PVCs use finalizers to prevent deletion while in use. PVCs have kubernetes.io/pvc-protection. PVs have kubernetes.io/pv-protection. These finalizers are removed only when the resource is no longer in use.
# Check PVC finalizers
kubectl get pvc my-claim -o yaml | grep finalizers
# If PVC is stuck in Terminating, check for finalizers
kubectl describe pvc my-claim
# Remove finalizer (only if safe)
kubectl patch pvc my-claim -p '{"metadata":{"finalizers":null}}'
kubectl patch pv my-pv -p '{"metadata":{"finalizers":null}}'Finalizers prevent accidental deletion. A PVC with a finalizer cannot be deleted while a Pod is using it. If a PVC is stuck in Terminating, check if a finalizer is preventing deletion. Only remove finalizers after ensuring data safety.
Use kubectl get pvc to see binding status. Bound means the PVC is ready. Pending means no matching PV exists. Lost means the PV was deleted. Use kubectl describe pvc for detailed binding information.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.