Kubernetes Storage — Dynamic Volume Provisioning

In Kubernetes, Dynamic volume provisioning is a mechanism which allows storage volumes to be created on-demand. Kubernetes Cluster uses concept of Storage class to achieve the same. Storage class another type of object in Kubernetes which allows you to abstract the details of underlying storage in a simple fashion. Kubernetes uses a system of persistent volume claim (PVC) and persistent volume (PV) to simplify storage operations with help of Storage Class (SC).

A cluster administrator can define as many StorageClass objects as needed, each specifying a volume plugin ( provisioner) that provisions a volume and the set of parameters to pass to that provisioner when provisioning.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fastdisk
provisioner: kubernetes.io/azure-disk
reclaimPolicy: Delete
volumeBindingMode: Immediate
parameters:
storageaccounttype: Premium_LRS
kind: Managed
#You can make any StorageClass as default, by adding the #storageclass.kubernetes.io/is-default-class annotation to it.

To access the Storage you must create the object PVC (PersistentVolumeClaim). PVC is the request to provision persistent storage with a specific type and configuration. PVC uses Storage class to create specific request to provisioner for storage creation. That’s it once PVC is in the system, rest of the things will be taken care by k8s cluster. ex: storage creation in cloud, PV creation and management etc.

This is dynamic volume provisioning !

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: storage-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: fastdisk
resources:
requests:
storage: 10Gi
Dynamic Provisioning

Creating a PVC in a cluster automatically triggers the storage plug-in for the requested type of storage to provision storage with the given specification.

You StorageClass will have storage account definition to use otherwise default storage account will be used to create storage.

Storage plug-in automatically creates a persistent volume (PV, virtual storage device) in the cluster, which maps to storage in Cloud. Status of the PVC and the PV changes to Bound

Now PVC Mounts that storage in POD if it is part of POD definition.

Storage Class

SC plays an important role in case of Dynamic provisioning. Each StorageClass has a provisioner that determines what volume plugin is used for provisioning PVs. Above mentioned SC defines Azure File Storage.

Another fieldreclaimPolicy defines what will happen to storage once you delete the PVC. Delete or Retain are two values which can be used here. As the name

The volumeBindingMode field controls when volume binding and dynamic provisioning should occur. Two values — Immediate or WaitForFirstConsumer

Immediate mode indicates that volume binding and dynamic provisioning occurs once the PersistentVolumeClaim is created.
WaitForFirstConsumer mode will delay the binding and provisioning of a PersistentVolume until a Pod using the PersistentVolumeClaim is created. This is useful when storage backends that are topology-constrained and not globally accessible. This Mode suits when you have a multi-zone cluster in place and storage is bound to Zones.

We will talk about more on WaitForFirstConsumer mode in next post.

That’s all for this post. Thanks.

Keep Learning !

In quest of understanding How Systems Work !

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store