tezvyn:

Kubernetes StorageClass: A Menu for Your Data

AI-drafted, machine-checkedSource: kubernetes.iointermediate
Kubernetes StorageClass: A Menu for Your Data

A StorageClass is an admin-defined 'menu' of storage options, abstracting the provider. Developers request storage by name (e.g., 'fast-ssd') via a PersistentVolumeClaim, and Kubernetes dynamically provisions it.

WHY IT EXISTS: In a large cluster, manually creating a physical storage volume for every application is slow and error-prone. StorageClass was created to automate this, allowing storage to be provisioned on-demand based on abstract requests, decoupling applications from the underlying storage infrastructure.

THE MENTAL MODEL: Think of a StorageClass as a restaurant menu. The menu lists different dishes ('fast-ssd', 'backup-storage') without detailing the kitchen's specific recipes or ingredient suppliers. A developer (the customer) orders a dish using a PersistentVolumeClaim (PVC). The cluster (the kitchen) then prepares the actual dish—a PersistentVolume (PV)—according to the recipe defined in the StorageClass.

HOW IT WORKS: An administrator defines a StorageClass resource in YAML. This definition includes a name (e.g., aws-gp3-fast), a provisioner (e.g., ebs.csi.aws.com), and parameters specific to that provisioner (e.g., type: gp3, fsType: ext4). When a user creates a PersistentVolumeClaim that references this StorageClass by name, the specified provisioner is triggered. It dynamically creates a matching PersistentVolume and binds it to the claim, making it available for a Pod to mount.

WHEN TO USE IT: Use StorageClasses whenever you need to provide persistent storage for stateful applications in Kubernetes. It is the standard, cloud-native way to manage storage lifecycles automatically, especially in public cloud environments like AWS, GCP, or Azure where storage options are API-driven. It's essential for enabling self-service for development teams.

WHEN NOT TO USE IT: You might not use dynamic provisioning via StorageClass if you are working with pre-existing, manually provisioned storage volumes that you need to map into the cluster. In this case, you would create PersistentVolume objects manually and have PVCs bind to them directly, without a StorageClass. This is common for migrating legacy stateful services or for specialized hardware.

ONE CANONICAL EXAMPLE: A major footgun is the reclaimPolicy. The default is Delete, which permanently destroys the underlying storage volume when the PVC is deleted. For production data, you almost always want to set reclaimPolicy: Retain to prevent accidental data loss. Another common issue is the default StorageClass. If a PVC is created without specifying a storageClassName, it uses the default, which might be an expensive tier of storage, leading to unexpected costs.

Read the original → kubernetes.io

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.