CodeBlanks Logo Icon CodeBlanks

Summary - PV and PVC

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. Retain keeps the data, Delete deletes 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-veri

Practice 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

terminal
# buraya yaz

Sample solution

terminal
kubectl get sc,pv,pvc
kubectl patch pvc api-veri -p '{"spec":{"resources":{"requests":{"storage":"10Gi"}}}}'
kubectl describe pvc api-veri

Expected 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.

Question
kubectl get ____,pv,pvc
Answer
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

All lessons in Advanced