A Pod needs a disk, but the default disk type may be too slow—or deleting a storage claim might erase data you need to keep. A StorageClass describes a category of storage that Kubernetes can provision on demand, including how its volumes are configured. A PersistentVolumeClaim (PVC) requests storage; its storageClassName selects the class. If no class is specified, the cluster’s default may be used. section 9.1.3
Two settings have especially practical consequences:
- The provisioner and parameters determine the backing storage. Parameter values can be platform-specific, so start with an existing class when configuring one for your cluster. section 9.1.3
- The reclaimPolicy determines what happens after a bound PVC is deleted. Delete also removes its PersistentVolume (PV) and backing disk; Retain preserves the disk but leaves unwanted disks for you to remove manually. section 9.1.3
Listing 9.4 Chapter09/9.1.3_StorageClass/storageclass.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
storageclass.kubernetes.io/is-default-class: "true" #1
name: example-default-rwo
parameters:
type: pd-balanced #2
provisioner: pd.csi.storage.gke.io
reclaimPolicy: Retain #3
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
#1 Optional annotation to set as default
#2 Platform-specific value to set the storage type
#3 Configured to preserve the disk if the PV is deleted
This StorageClass uses a platform-specific disk type and a Retain policy. Its default-class annotation is optional; check existing defaults before making another class the default. section 9.1.3
Run kubectl get storageclass to see available classes and their reclaim policies. For important data, verify that the class used to create the disk has Retain set before relying on recovery. Deleting a StatefulSet does not itself delete its PVCs, but deleting those PVCs can delete their disks when the policy is Delete. section 9.1.3 section 9.3
Preserve or discard the disk?
A Redis StatefulSet holding valuable data uses a Retain class. Even if its Kubernetes storage objects are removed, the preserved cloud disk can be linked to newly created PV and PVC objects, including in another cluster; recovery requires that manual work. A Pod using a generic ephemeral volume for scratch space instead uses a Delete class: deleting the Pod removes its PVC and cleans up the disk. Choose the policy for the data’s intended lifetime, not simply for the application type. section 9.3 section 9.4
Listing 9.12 Chapter09/9.4_EphemeralVolume/ephemeral_storageclass.yaml
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: ephemeral parameters: type: pd-ssd #1 provisioner: pd.csi.storage.gke.io reclaimPolicy: Delete #2 volumeBindingMode: WaitForFirstConsumer allowVolumeExpansion: true
For temporary scratch space, this separate StorageClass requests SSD-backed storage and sets reclaimPolicy to Delete so the disk is not retained after use. section 9.4



