Storage Classes and Dynamic Provisioning

Let's look at Storage Classes' YAMLs and how to implement them.

Everything you’ve seen so far is correct and fundamental to Kubernetes storage. But it doesn’t scale – there’s no way somebody managing a large Kubernetes environment can manually create and maintain large numbers of PVs and PVCs. You need something more dynamic.

Enter storage classes:

As the name suggests, storage classes allow you to define different classes, or tiers, of storage. How you define your classes is up to you, but it will depend on the types of storage you have access to. For example, you might define a fast class, a slow class, and an encrypted class (your external storage system would need to support different speeds of storage and support encrypting volumes, as Kubernetes does none of this).

As far as Kubernetes goes, storage classes are defined as resources in the storage.k8s.io/v1 API group. The resource type is StorageClass, and you define them in regular YAML files that you POST to the API server for deployment. You can use the sc shortname to refer to StorageClass objects when using kubectl.

Note: You can see a full list of API resources and their shortnames using the kubectl api-resources command. The output of the command shows the API group that each resource belongs to (an empty string indicates the core API group), whether or not the resource is namespaced and what its equivalent kind is when writing YAML files.

Get hands-on with 1200+ tech skills courses.