Static and Dynamic Provisioning in Kubernetes

Harish SharmaHarish Sharma
4 min read

In Kubernetes, storage provisioning refers to the process of creating storage resources, such as PersistentVolumes (PVs), which can then be used by applications within the cluster. Kubernetes offers two main types of provisioning: dynamic provisioning and static provisioning. These approaches manage storage differently based on how PersistentVolumes are created and allocated to applications. Let’s delve into each and highlight their differences.


Static Provisioning

Static provisioning is a traditional approach where a cluster administrator manually creates PersistentVolumes (PVs) in advance. These PVs are pre-configured and are available to be claimed by PersistentVolumeClaims (PVCs) when applications request storage.

How It Works

  1. Administrator Creates PVs: The administrator manually defines and creates PersistentVolumes with specific storage requirements (such as capacity, access modes, and storage class).

  2. User Requests Storage via PVC: When a user or application needs storage, they create a PersistentVolumeClaim (PVC) specifying the required capacity and access mode.

  3. Binding Process: Kubernetes tries to match the PVC with an available PV that meets its requirements. If a suitable PV is found, it is bound to the PVC.

Example of Static Provisioning

  1. PersistentVolume (PV):

     yamlCopy codeapiVersion: v1
     kind: PersistentVolume
     metadata:
       name: pv-static
     spec:
       capacity:
         storage: 5Gi
       accessModes:
         - ReadWriteOnce
       persistentVolumeReclaimPolicy: Retain
       storageClassName: manual
       hostPath:
         path: "/mnt/data"
    
  2. PersistentVolumeClaim (PVC):

     yamlCopy codeapiVersion: v1
     kind: PersistentVolumeClaim
     metadata:
       name: pvc-static
     spec:
       accessModes:
         - ReadWriteOnce
       resources:
         requests:
           storage: 5Gi
       storageClassName: manual
    

In this example:

  • The PV pv-static is created manually with 5Gi of storage.

  • When the PVC pvc-static requests 5Gi of storage with ReadWriteOnce access mode, it will be bound to pv-static, assuming no other claim has already bound to it.

Key Points of Static Provisioning

  • Manual Process: Administrators must manually create and manage PVs.

  • Pre-defined Storage: The storage is pre-allocated and may sit unused if no application requires it.

  • Best for Fixed Requirements: Works well in environments where storage needs are predictable and don’t change frequently.


Dynamic Provisioning

Dynamic provisioning automates the creation of storage volumes when they are requested by applications, eliminating the need for administrators to pre-create PVs. Kubernetes dynamically provisions the necessary PVs when a PersistentVolumeClaim (PVC) is created.

How It Works

  1. User Requests Storage via PVC: The user or application creates a PVC specifying the required capacity, access mode, and storage class.

  2. Automatic Provisioning of PV: Based on the StorageClass defined in the PVC, Kubernetes uses a storage provisioner to dynamically create a PV that satisfies the PVC’s requirements.

  3. Binding Process: The dynamically provisioned PV is then bound to the PVC.

Example of Dynamic Provisioning

  1. StorageClass:

     yamlCopy codeapiVersion: storage.k8s.io/v1
     kind: StorageClass
     metadata:
       name: dynamic-storage
     provisioner: kubernetes.io/aws-ebs # or another provisioner like gcePersistentDisk, csi, etc.
     parameters:
       type: gp2
    
  2. PersistentVolumeClaim (PVC):

     yamlCopy codeapiVersion: v1
     kind: PersistentVolumeClaim
     metadata:
       name: pvc-dynamic
     spec:
       accessModes:
         - ReadWriteOnce
       resources:
         requests:
           storage: 10Gi
       storageClassName: dynamic-storage
    

In this example:

  • A StorageClass named dynamic-storage is defined, which uses the AWS EBS provisioner.

  • When pvc-dynamic requests 10Gi of storage, Kubernetes dynamically provisions a PV with 10Gi capacity using AWS EBS (based on the provisioner defined in StorageClass), and the new PV is bound to pvc-dynamic.

Key Points of Dynamic Provisioning

  • Automatic Process: The cluster automatically provisions PVs when PVCs are created.

  • On-Demand Storage: Storage is created only when needed, reducing wasted resources.

  • Flexible and Scalable: Ideal for cloud-native applications and environments with varying storage needs.


Differences Between Static and Dynamic Provisioning

AspectStatic ProvisioningDynamic Provisioning
PV CreationManually created by an administratorAutomatically created by Kubernetes
FlexibilityLimited, with pre-defined storage volumesFlexible, with storage provisioned on-demand
Effort RequiredHigh, as PVs must be managed manuallyLow, as Kubernetes handles PV creation automatically
Use CasesPredictable, stable storage needsDynamic, cloud-native, or unpredictable workloads
Resource EfficiencyMay result in unused storage, as PVs are pre-allocatedResource-efficient, only provisions as needed

Use Cases for Each

  • Static Provisioning:

    • Suitable for environments with predictable workloads, such as legacy applications or databases with fixed storage requirements.

    • Useful when administrators want strict control over storage allocation.

  • Dynamic Provisioning:

    • Ideal for cloud-native applications and microservices architectures where storage needs are dynamic and frequently changing.

    • Works well in cloud environments where storage provisioners (like AWS EBS, GCE Persistent Disks) are available.


Summary

  • Static Provisioning is best when you need strict control over storage and have predictable storage requirements. It’s manually intensive but ensures that storage is available in advance.

  • Dynamic Provisioning automates storage provisioning, making it ideal for scalable, dynamic environments. It allows for flexible, on-demand storage creation, reducing manual overhead and waste.

Using dynamic provisioning whenever possible can simplify storage management and improve resource efficiency in a Kubernetes cluster.

0
Subscribe to my newsletter

Read articles from Harish Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harish Sharma
Harish Sharma

Devops Engineer.