This article explains dynamic and static storage provisioning in Kubernetes and OpenShift using the Container Storage Interface and provides configuration examples.
Before diving into OpenShift terminology, it helps to review storage from a Kubernetes perspective. The underlying concepts for both Kubernetes and OpenShift are very similar, which makes it easy to transition between the two.The Kubernetes storage system relies on the Container Storage Interface (CSI) plugin. This plugin enables direct communication between Kubernetes (or OpenShift) and various storage providers, including Azure Storage, AWS S3, and NetApp Storage—as long as the vendor supports the respective plugin.One key component in this process is the provisioner. Think of it like a parent-child relationship where the dynamic provisioner acts as the first child, directly interacting with the CSI plugin. This dynamic connection is established through a StorageClass. For example, you could create an Azure StorageClass for dynamically connecting to either Azure File Shares or Azure Disks.In addition to dynamic provisioning, Kubernetes also supports static provisioning using PersistentVolumes (PVs). In static provisioning, you define a fixed disk (such as a 50-GB disk) within a PersistentVolume, and then allow a Pod to claim this volume using a PersistentVolumeClaim (PVC). In both scenarios, the PVC is responsible for requesting storage either from a StorageClass (dynamic provisioning) or from a pre-configured PersistentVolume (static provisioning).
In OpenShift, “persistent storage” essentially refers to a PersistentVolume in Kubernetes. Although the terminology may differ, the underlying functionality remains the same.
Let’s illustrate these concepts with an example in Visual Studio Code. The following YAML configuration defines a StorageClass using the CSI for Azure Files, along with a PersistentVolumeClaim that requests 10 Gi of storage:
The StorageClass “azurefile-csi” uses the file.csi.azure.com provisioner, designed specifically for Azure Files.
Various mount options and parameters (e.g., skuName: Premium_LRS) customize the storage settings.
The PersistentVolumeClaim named “azurefile” requests 10 Gi of storage through the defined StorageClass.
When the PVC is created, it communicates with the StorageClass to allocate the requested storage. Once available, the PVC binds to the provisioned storage, making it ready for use by a Kubernetes deployment.Below is an example snippet that demonstrates how to reference the PersistentVolumeClaim within a Kubernetes deployment. In this configuration, the volume is mounted into a Pod:
The volume “azure” references the PersistentVolumeClaim named “azurefile”.
The Nginx container mounts this volume at the directory /mnt/azure.
This approach to storage provisioning—whether dynamic or static—ensures that you can manage storage resources efficiently across both Kubernetes and OpenShift environments.Let’s check it out.