CKAD field manual

Kubernetes StorageClass YAML example

A StorageClass names how a claim gets a disk. A claim that names no class takes the default. The class is cluster-wide.

A deck officer rests a hand on small lockers inside a lit ring, while bulk containers and chained crates wait in the dark. A deck officer rests a hand on small lockers inside a lit ring, while bulk containers and chained crates wait in the dark.
StorageClass
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: rancher.io/local-path
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
Leave one default
kubectl get sc
kubectl patch sc local-path -p '{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
Grow a claim
kubectl patch sc fast -p '{"allowVolumeExpansion":true}'
kubectl patch pvc data -p '{"spec":{"resources":{"requests":{"storage":"2Gi"}}}}'

Fields

provisioner
The plugin that creates the volume. Use the string the task names. kubernetes.io/no-provisioner creates nothing.
reclaimPolicy
Delete or Retain, copied onto the new volume. The default is Delete. Fixed after create.
volumeBindingMode
Immediate binds now. WaitForFirstConsumer waits for a Pod. The default is Immediate. Fixed after create.
allowVolumeExpansion
true lets a claim grow. Patch this field, then raise requests.storage. A claim cannot shrink.
storageclass.kubernetes.io/is-default-class
“true” marks the default. Set the other class to “false”. A claim that omits storageClassName takes the newest default.
kubectl get
(default) is the class a claim uses when it omits storageClassName. The first column is the name.
kubectl patch
Sets the default annotation, or allowVolumeExpansion. provisioner, reclaimPolicy, and volumeBindingMode are rejected.

Watch

  • storageclass.kubernetes.io/is-default-class set to “true” marks the default. Any other value, or no annotation, does not. A claim that omits storageClassName takes the newest class marked default. Set the previous class to “false”. Claims that already exist keep their class.
  • provisioner, parameters, reclaimPolicy, and volumeBindingMode are fixed at create. Delete the StorageClass and create it again. allowVolumeExpansion can be patched. Then raise the claim’s requests.storage. The claim cannot shrink, and the provisioner has to support expansion.
  • volumeBindingMode defaults to Immediate, which binds as soon as a volume matches. WaitForFirstConsumer stays Pending until a Pod uses the claim. kubernetes.io/no-provisioner creates no disk. You write the PersistentVolume, and storageClassName matches on both.
  • A StorageClass has no namespace. reclaimPolicy defaults to Delete and is stamped on volumes this class provisions. A volume written by hand keeps its own persistentVolumeReclaimPolicy. An empty storageClassName on a claim binds only to a volume with an empty class. Omit the field and, when a class is marked default, that class is filled in.

Official docs Storage Classes Change the default StorageClass

Practice these objects on a live cluster →