Kubernetes Storage Provisioning
Kubernetes storage provisioning refers to the process of dynamically or statically allocating storage resources to applications running in a kubernetes cluster.
In a containerized environment, where applications are often ephemeral and can be scaled up or down rapidly, efficient storage management is crucial. Kubernetes provides a flexible storage system that allows developers to request and use storage resources are needed.
In this article, we’ll explore the concepts of dynamic and static provisioning, the roles of PVs and PVCs and pivotal role played by storage classes in kubernetes.
Storage Provisioning in Kubernetes:
- Persistent Volumes (PV):
PVs are cluster-wide resource that represents a piece of storage, provisioned dynamically or statically. It abstract the underlying storage infrastructure and allow applications to consume storage. - Persistent Volume Calims (PVC):
PVC is a request of storage by user or pod, PVCs consume PV resources and provide a way for user to request specific levels of storage. Users define the storage class, access modes and storage capacity they need and kubernetes finds a suitable PV to bind to the claim. - Storage Class (SC):
Storage classes is a configuration template in k8s, abstracting storage details and facilitating dynamic provisioning of storage resources based on user-defined characteristics.
Provisioner: Provisioner is resposible for dynamically provisioning storage volumes based on specifications provided in a PVC.
Provisioner creates and manage actual storage resources based on PVCs requirements. - CSI Driver: It acts as an interface between k8s and underlying storage infrastructure, supports various storage operations, including dynamic provisioning, attaching and detach storage volumes.
A provisioner often uses a CSI driver as its underlying mechanism to interact with specific storage systems. The provisioner defines how to create and manage volumes, while the CSI driver handles the communication and integration with the storage infrastructure
Types of Storage Provisioning:
Static Provisioning:
— The PVs are created manually by the cluster administrator or through some automation, independent of PVCs or Storage Classes, offering control and predictability.
— Users explicitly reference pre-existing PVs in their PVCs, allowing for specific resource allocation.
Dynamic Provisioning:
— Dynamic provisioning allows storage to be automatically allocated based on user demand.
— The PVC is responsible for specifying the desired storage capacity, access modes, and referencing a Storage Class for dynamic provisioning.
— The Provisioner (CSI Driver) is responsible for interacting with the underlying storage system and dynamically creating the storage volume based on the PVC’s specifications.
— The PV is created automatically by the provisioner in response to the PVC’s request.
Dynamic Provisioning Flow:
User Request (PVC): Users create PVCs to request storage with specific characteristics.
PVC References Storage Class:
The PVC references a Storage Class, specifying provisioning details like the provisioner, access modes, and additional parameters.
Provisioner Triggers Dynamic Provisioning:
The Storage Class’s provisioner is triggered which is associated with a specific storage class, initiating the dynamic provisioning process.
Provisioner Interacts with CSI Driver:
The provisioner, associated with a CSI (Container Storage Interface) driver, communicates with the underlying storage infrastructure.
Dynamic Creation of PV:
Based on PVC and Storage Class specifications, the provisioner dynamically creates a Persistent Volume (PV) within the Kubernetes cluster.
PVC Binds to Dynamically Created PV:
The PVC that initiated the dynamic provisioning process is automatically bound to the dynamically created PV.
Static Provisioning Flow:
Administrator Creates PV:
A cluster administrator manually creates a Persistent Volume (PV), specifying details like capacity, access modes, and storage location.
User Creates PVC:
Users create Persistent Volume Claims (PVCs) to consume storage from specific pre-existing PVs.
PVC References Pre-Existing PV:
The PVC explicitly references the name of the pre-existing PV, indicating the desired storage resource.
In PVC configuration, for the field of storageClassName value should be set empty string, otherwise default storageClass is selected from your cluster.
Example:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: foo-pvc
namespace: foo
spec:
storageClassName: "" # Empty string must be explicitly set otherwise default StorageClass will be set
volumeName: foo-pv
Manual Binding of PVC to PV:
The user manually binds the PVC to the pre-existing PV, specifying the PV's name or using a selector that matches the PV's labels.
In this Static storage provisioning, Storage Class is optional
Conclusion:
In summary, our exploration has provided a clear understanding of storage provisioning in Kubernetes, covering different types and shedding light on the roles of PVs, PVCs, Storage Classes, and CSI drivers.