An app does not want a disk. It wants "1 GB, that I can write". That request is a PersistentVolumeClaim.
The claim
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: market-data
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 1Gi| Field | Means |
|---|---|
accessModes | How it will be mounted; ReadWriteOnce is one node, read and write |
resources.requests.storage | At least this much |
storageClassName | Which class provides it (next lesson); omitted means the default |
A claim is namespaced and pvc is its short name.
Bound or Pending
text
learner@shallows:~$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS
market-data Pending local-path
market-data Bound pvc-5b1e0c7a-8d3f-4f8a-9d4e-2c6b1a7f0e21 1Gi RWO local-pathA claim starts Pending. Something has to bind it to a volume: the class's provisioner creates one, or an administrator's volume fits it. describe pvc says what it waits for:
text
Events:
Normal WaitForFirstConsumer persistentvolume-controller waiting for first consumer to be created before bindingMount the claim
yaml
spec:
containers:
- name: db
image: postgres:16
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
volumes:
- name: data
persistentVolumeClaim:
claimName: market-dataThe Pod names the claim. Delete the Pod and the claim stays Bound; the next Pod that names it gets the same data. Only kubectl delete pvc lets the data go.