StorageClass
- Docker & Kubernetes course
- Advanced
- Lesson 33/70
- 4 min
Learn dynamic provisioning with a StorageClass.
StorageClass
A StorageClass lets PVs be created dynamically (automatically when a request arrives). It defines which provider (CSI driver) opens a disk with which settings. A PVC chooses the class with storageClassName; if it doesn't write one, the default class is used:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: hizli-ssd
provisioner: ebs.csi.aws.com
parameters:
type: gp3
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumerDefault class and expansion
kubectl get storageclass marks the default class with (default). In classes with allowVolumeExpansion: true, a PVC can be grown (not shrunk):
$ kubectl get storageclass
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE
standard (default) k8s.io/minikube-hostpath Delete Immediate
hizli-ssd ebs.csi.aws.com Delete WaitForFirstConsumer
$ kubectl patch pvc api-veri -p '{"spec":{"resources":{"requests":{"storage":"10Gi"}}}}'Practice A fast SSD class
Write a StorageClass YAML: apiVersion: storage.k8s.io/v1; name hizli-ssd; provisioner: ebs.csi.aws.com; parameters.type: gp3; allowVolumeExpansion: true; volumeBindingMode: WaitForFirstConsumer.
Starter code
# buraya yazSample solution
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: hizli-ssd
provisioner: ebs.csi.aws.com
parameters:
type: gp3
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumerExpected output
storageclass.storage.k8s.io/hizli-ssd created
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does volumeBindingMode: WaitForFirstConsumer do?
- It deletes the PVC
- It makes the disk read-only
- It creates the disk immediately
- It delays creation until a pod exists, so the disk opens in the zone the pod is scheduled to Correct answer
Explanation: Cloud disks are usually tied to a single availability zone.
2 Specify the driver that opens the disks.
kind: StorageClass
metadata:
name: hizli-ssd
____: ebs.csi.aws.com
kind: StorageClass
metadata:
name: hizli-ssd
provisioner: ebs.csi.aws.com
Explanation: provisioner is the CSI driver's name.
3 Match.
| Term | Meaning |
|---|---|
StorageClass |
Dynamic PV template |
provisioner |
CSI driver |
allowVolumeExpansion |
Allow growing |
(default) |
Default class |