Kubernetes Storage Classes – A Comprehensive Overview for Beginners

Storage classes provide a flexible way to manage storage for stateful workloads. They allow you to customize storage for your specific requirements and align them with costs in your cluster.

Kubernetes storage class provisions are dynamically bound to Persistent Volumes (PVs) created by that StorageClass, depending on the reclaimPolicy set in that StorageClass object. This ensures that PVCs will be provisioned as soon as they’re requested.

Default Storage Class

Storage is the foundation of Kubernetes, allowing it to support all applications. It’s important to understand the different options available for managing storage effectively.

Kubernetes allows administrators to provision persistent storage for their applications dynamically on-demand. This functionality is enabled by a feature called storage classes. Storage classes can reduce the time and effort required to deploy and manage applications in a Kubernetes cluster.

A StorageClass is a resource that defines the capabilities of a storage system, such as disk format, availability zone, and volume bind mode. It can also contain a provisioner that decides which volume plugin to use to provision PersistentVolumes. In addition, it can define access policies such as retain and delete. A default StorageClass is defined during the installation of a new Kubernetes cluster. A PersistentVolumeClaim that doesn’t specify a StorageClass will be fulfilled by the default StorageClass.

It’s important to select the right StorageClass for your application needs. A good place to start is by reviewing your storage requirements and the capabilities of the underlying storage system. Using a YAML linter or validator is also recommended to ensure that your StorageClass configuration is well-formed. Errors in the YAML file can cause misconfiguration and result in unusable StorageClasses. This can impact the performance and reliability of your applications.

Persistent Volume Claim (PVC)

The persistent volume claim (PVC) is an object that represents a request for a storage resource made by a pod. PVCs do not control the underlying storage; they just define its requirements. For example, a PVC might specify a disk size and access mode. The cluster then matches the PVC to a PV that can satisfy those requirements. The match is not exact – for example, a PVC that requests shared storage might be bound to a single-access PV.

A PVC also contains information about what should happen to the underlying PV when the user is done with it. This is known as its reclaim policy and can be either Removed or Removed. The default is Retain, meaning the underlying PV and data remain intact even after the PVC is deleted. This helps protect against accidental loss of important data.

When an administrator creates a StorageClass, they can specify which reclaim policy it should have. The default is Delete, but this can be changed by creating a new StorageClass with the appropriate reclaim policy. The storage reclaim policy is only applied to PVCs created by the StorageClass and not to manual ones. Hence, when a storage class is deleted, the admin must reclaim its underlying resources manually. The reclaim policy also applies to the underlying PVs that the StorageClass dynamically provisions.

Persistent Volume (PV)

A persistent volume (PV) is a storage object for storing data in the Kubernetes cluster. It can be statically provisioned by administrators or dynamically provisioned based on StorageClasses that developers specify when creating PersistentVolumeClaims.

A PV can have a hostPath or a filesystem mode. It also has a capacity, specifying the storage space available. 

Each PV has a status that indicates its current state. Its status can be Available, Bound, Reclaiming, Retaining, or Failed. If the reclaiming policy of a StorageClass is set to Retain, the PV cannot be deleted until it has been unused for some time, usually 30 days.

You can check the status of a PV by using kubectl describe persistent name>. A PV’s spec can contain several attributes, including node affinity or taints, to define constraints for where the pod should be scheduled. If a PV’s specs do not match the expected behavior of your Kubernetes implementation, try changing it to something more compatible. You can also monitor changes to your cluster’s storage configuration using a Spacelift tool. This tool can help you visualize your cluster’s storage and set up guardrails to prevent accidental changes.

Persistent Volume Claims (PVC Claims)

Users who create a PVC specify the requested storage size and access mode. The master has a control loop that monitors these new requests, finds matching PVs (if any), and binds them together. Once a PV is bound to a Persistent Volume Claim, the cluster reserves it for the user and can only be used by that workload.

PVs may be reclaimed after the use of a workload expires. When the user deletes the PVC from the cluster, Kubernetes automatically reclaims the storage. The cluster uses its reclaim policy to determine what to do with the PV–retain, recycle, or delete it.

If a PVC specifies a default StorageClass, that class is assigned. This prevents the user from overriding the StorageClass, which could have unintended consequences for other workloads. To avoid overriding the default StorageClass, pre-bind PVs to a Persistent Volume Claim. This is a more cumbersome process because you must create the PV and its associated PVC while ensuring their properties match. However, it can be a useful way to delay PV binding until Pod scheduling, which is important for scaling applications that require different amounts of local storage across node sizes.

Leave a Comment