Summary - PV and PVC
- Docker & Kubernetes course
- Advanced
- Lesson 36/70
- 5 min
Combine PV, PVC and mount to set up persistent storage.
Summary: PV and PVC
In this group:
- A PV is a piece of storage in the cluster; it lives independently of pods.
Retainkeeps the data,Deletedeletes the disk. - A PVC is a storage request; it is bound to a suitable PV (
Bound). - A StorageClass creates PVs dynamically:
provisioner,parameters,allowVolumeExpansion,WaitForFirstConsumer. - Access modes: RWO, ROX, RWX, RWOP; an RWO disk attaches to a single node (Multi-Attach error).
- A pod mounts a PVC with
persistentVolumeClaim.claimName; the data stays when the pod is deleted.
kubectl get sc,pv,pvc
kubectl describe pvc api-veriPractice Grow the storage
Write three commands: list the StorageClasses, PVs and PVCs in one command; grow the api-veri PVC with the patch {"spec":{"resources":{"requests":{"storage":"10Gi"}}}}; show api-veri in detail.
Starter code
# buraya yazSample solution
kubectl get sc,pv,pvc
kubectl patch pvc api-veri -p '{"spec":{"resources":{"requests":{"storage":"10Gi"}}}}'
kubectl describe pvc api-veriExpected output
NAME PROVISIONER storageclass.storage.k8s.io/standard (default) k8s.io/minikube-hostpath NAME CAPACITY STATUS CLAIM persistentvolume/pvc-9c1d… 5Gi Bound default/api-veri persistentvolumeclaim/api-veri patched Name: api-veri Capacity: 10Gi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 A PVC stays Pending and the event says "storageclass not found". What is the fix?
- Correcting storageClassName to an existing class or creating that class Correct answer
- Restarting the pod
- Shrinking the size
- Changing the namespace
Explanation: kubectl get storageclass lists the existing classes.
2 List the StorageClasses, PVs and PVCs together.
kubectl get ____,pv,pvc
kubectl get sc,pv,pvc
Explanation: sc is the abbreviation of storageclasses.
3 Match.
| Term | Meaning |
|---|---|
PV |
Storage |
PVC |
Request |
StorageClass |
Automatic creation |
claimName |
Pod link |