PersistentVolumeClaim
- Docker & Kubernetes course
- Advanced
- Lesson 32/70
- 4 min
Learn storage requests with a PVC.
PersistentVolumeClaim
A PersistentVolumeClaim (PVC) is an application's storage request: "5 GiB, writable by a single node". Kubernetes finds a PV matching the request and binds it (Bound) or creates a new one with a StorageClass. The application developer doesn't need to know infrastructure details (which disk, which cloud):
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: api-veri
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
storage: 5Gi
States
A PVC's state is Pending (no suitable PV, or waiting to be created) or Bound. The reason a PVC stays Pending is seen in the describe events:
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS
api-veri Bound pvc-9c1d… 5Gi RWO standard
eski Pending hizli-ssd
$ kubectl describe pvc eski | tail -2
Warning ProvisioningFailed storageclass.storage.k8s.io "hizli-ssd" not foundPractice Write a PVC
Write a PersistentVolumeClaim YAML: name api-veri; ReadWriteOnce under accessModes; storageClassName: standard; resources.requests.storage: 5Gi.
Starter code
# buraya yazSample solution
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: api-veri
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
storage: 5GiExpected output
persistentvolumeclaim/api-veri created NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS api-veri Bound pvc-9c1d… 5Gi RWO standard
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the relationship between a PV and a PVC?
- A PVC is a request; Kubernetes binds a PV matching it Correct answer
- A PVC is a backup of a PV
- The PV is inside the PVC
- They are unrelated
Explanation: Binding is one-to-one: a PV is bound to only one PVC at a time.
2 Write the requested storage amount.
resources:
requests:
____: 5Gi
resources:
requests:
storage: 5Gi
Explanation: requests.storage is the size the PVC requests.
3 Match.
| Term | Meaning |
|---|---|
PVC |
Storage request |
PV |
Actual storage |
Bound |
Bound |
Pending |
Waiting for a suitable PV |