Kubernetes Storage : Overview of Storage Classes ☸☸

Everything about Storage in Kubernetes :))

Vibhor Chinda
Google Cloud - Community
5 min readApr 9, 2023

--

Introduction 🚩🚩

Hi fellow Readers 👋 :))
I have been writing about the overview of Kubernetes concepts and it’s objects for a while now. In the last edition of my Technical article, I wrote about some concepts related to Storage in Kubernetes.

Continuing on the lines of my previous article, Today I will be again writing about another major concept called Storage Classes.

Storage Classes is another important and fun concept which is related to Storage in Kubernetes.

So In this article, we will try to learn about :

  • What exactly is Dynamic Provisioning ??
  • What are Storage Classes in Kubernetes ??
  • How to use and configure Storage Classes ??

It will be a small but an extremely interesting article.
So without any further delay, lets get started with it 🐵

What exactly is Dynamic Provisioning ?? 🤔🤔

Photo by D koi on Unsplash

In the world of Kubernetes Storage, Provisioning basically means to keep aside some space in the storage provider which is being used by the organization and allocate that space to develop Persistent Volumes (PV) there.
Persistent Volumes which gets provisioned, are later being claimed by the respective PODs to run various applications with the help of different Persistent Volume Claim (PVC).

I won’t go much deep in the concepts of Persistent Volume (PV) and Persistent Volume Claim (PVC) here as it would deviate us from the topic but it is kind of a pre-requisite to know before moving to the concept of Storage Classes.

So if anyone’s interested to read about them before moving forward. Please refer my previous article, I have discussed thoroughly about thse concepts there :)

Moving forward, we now know what does the term Provisioning means in the Kubernetes world. Let’s now discuss what are the two different types of Provisioning of PVs.

  1. Static Provisioning
    It is the method in which the cluster administrator provisions PVs manually.
  2. Dynamic Provisioning
    It is the method in which the cluster administrator doesn’t provision the PVs manually beforehand. Rather in this process, whenever a POD requires some storage space, the Kubernetes cluster then and there provision the required PV for that POD and allocate that PV to it.

What are Storage Classes in Kubernetes ?? 😐😐

When none of the static PVs the administrator created match a user’s Persistent Volume Claim, the cluster may try to dynamically provision a volume specially for the PVC.
This provisioning is based on Storage Classes, the PVC must request a storage class and the administrator must have created and configured that storage class for dynamic provisioning to occur.

So if we try to understand about Storage Classes in simple points, then we would find that :

  • Storage Class allows dynamic provisioning of Persistent Volumes, when PVC claims it.
  • Storage Class abstracts underlying storage provider.
  • Storage Class is used in conjunction with PVC that allow Pods to dynamically request a new storage.
  • Storage Class use provisioners that are specific to the storage platform or cloud provider to give Kubernetes access to the physical storage.
  • Each storage backend has own provisioner. Storage Backend is defined in the Storage Class component via provisioner attribute.

How to use and configure Storage Classes ?? 🍃 🍃

Photo by Kevin Horvat on Unsplash

We can create Storage Class using YAML files. To create a Storage Class with YAML, you first create an empty file, assign it the necessary access permissions, and then define the necessary key-value pairs.

Below is an example of a Storage Class definition file (storage_class.yaml)

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: google-storage
provisioner: kubernetes.io/gce-pd

There are many aspects and components in this file. Lets break down each one of them 😀

  • Let’s start with the apiVersion (key-value pair). This is used to clarify what API server and version you will be running in the background when creating the Storage Class.
  • Next is kind which signifies the kind of definition file this is. In our case, it is a “StorageClass”.
  • Next is metadata, which is a dictionary including the item name and labels. The metadata stores values that are assigned to the Storage Class which is being created.
  • Finally there is provisioner attribute which basically defines the name of the Storage Provider where PVs will be provisioned. For example AWS, vSphere, OpenStacketc

We are done with the Storage Class definition file. Now we can save and exit the file.

Use this command to create the Storage Class based on the above YAML file :

kubectl create -f storage_class.yaml

Use this command to list all the Storage Classes :

kubectl get sc

Now we have successfully learnt to create the StorageClass :))

To actually use this StorageClass, define the name of StorageClass in the Persistent Volume Claim (PVC) definition file under the specsection for the storageClassName attribute.

What next ?? 👀 👀

Thanks a lot for reaching till here! This is the end of this article.
But we have only scratched the surface of the K8s ecosystem :))
Much more to go, it will be a fun journey where we will learn a lot of cool stuff together.

Do clap and follow me 🙈 if you like my writings and want to read more from me in the future :))

In case of any doubts around this article or for some general chit chat, feel free to reach out to me on my social media handles

Twitter — https://twitter.com/ChindaVibhor

LinkedIn — https://www.linkedin.com/in/vibhor-chinda-465927169/

Related Articles

I will still keep on coming with new articles covering a bunch of topics I am exploring.

That’s All folks !! Doodles :))

--

--

Vibhor Chinda
Google Cloud - Community

Software Developer 2 @Guidewire | Ex - VMware | CKA | Exploring Cloud Tech | Developing Patience ✨✨