1. Basic Concepts
- PV (PersistentVolume): A storage resource pre-configured by the administrator or dynamically created by a StorageClass, representing actual storage in the cluster.
- PVC (PersistentVolumeClaim): A user’s request for storage, specifying required capacity, access modes, etc.
2. Binding Conditions
The binding between PVC and PV must meet the following conditions:
- Capacity (storage)
- The PV’s capacity must be greater than or equal to the PVC’s requested capacity.
- Access Modes
- Common modes:
ReadWriteOnce(read/write by a single node)ReadOnlyMany(read-only by multiple nodes)ReadWriteMany(read/write by multiple nodes)
- The PV must support the access mode requested by the PVC.
- Common modes:
- StorageClass
- If the PVC specifies
storageClassName, it will only bind to PVs with the same name. - If not specified, it binds to PVs with no storage class or the default storage class.
- If the PVC specifies
3. Reclaim Policy
The reclaim policy of a PV determines how the PV is handled after the PVC is released:
Retain: The PV and its data are not deleted; manual handling is required.Recycle: Deprecated. Used to simply clear data and make the PV available again.Delete: The PV and its backend storage resource are automatically deleted (e.g., cloud disks).
The delete policy is only supported for storage types provided by cloud vendors, such as AWS EBS, GCE Persistent Disk, etc.
4. PV/PVC States
PV States
Available: Not bound to a PVC, availableBound: Bound to a PVCReleased: PVC deleted, but resource not yet reclaimedFailed: Automatic reclamation failed
PVC States
Pending: Not bound to a PVBound: Bound to a PVLost: The bound PV is unavailable
5. PVC Protection
Kubernetes provides PVC protection to prevent PVCs in use by Pods from being accidentally deleted:
- When a PVC is mounted by a Pod, deletion is blocked until the PVC is no longer used by any Pod.
- Implemented via the PVC’s
finalizerfield.
6. Removing PV Binding State
To remove the binding state of a PV, follow these steps:
- Edit the PVC’s
spec.claimReffield to be empty.
bash
kubectl edit pvc <pvc-name>- Delete and recreate the PV.
bash
kubectl delete pv <pv-name>
kubectl apply -f <pv-definition-file>7. Example YAML
yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-demo
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
storageClassName: manual
hostPath:
path: /mnt/data
persistentVolumeReclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-demo
spec:
accessModes:
- ReadWriteOnce
storageClassName: manual
resources:
requests:
storage: 500Mi8. Common Issues and Suggestions
- For production, use dynamic StorageClass
- Pay attention to PV/PVC lifecycle and data safety
- Regularly check PV status to avoid resource leaks