Understanding Kubernetes Storage - PV, PVC, StorageClass, and CSI-Driver

A comprehensive guide to Kubernetes storage components and their interactions

Featured image

Image-Reference-link



Overview

This guide explores Kubernetes storage components, including Persistent Volumes (PV), Persistent Volume Claims (PVC), StorageClass, and Container Storage Interface (CSI) drivers.


Kubernetes Volumes

graph TD; Provisioning --> Binding; Binding --> PV["Persistent Volume (PV)"]; PV --> Retain["Retain Policy"]; PV --> Delete["Delete Policy"]; PV --> Recycle["Recycle Policy"]; PV --> PVC["Persistent Volume Claim (PVC)"]; PV --> SC["Storage Class"]; PV --> CSI["CSI-Driver"]; Retain --> Pod; PVC --> Using; Using --> Releasing; Releasing --> Reclaiming; SC --> Dynamic["Dynamic Provisioning"]; SC --> Static["Static Provisioning"]; CSI --> Block["Block Storage"]; CSI --> File["File Storage"]; CSI --> Object["Object Storage"]; SC -->|Can specify| PVC; CSI -->|Managed by| SC;

Persistent Volumes (PV)

Key Characteristics
  • Cluster-level storage resources provisioned by administrators or dynamically via StorageClass
  • Independent lifecycle from pods
  • Abstracts storage provisioning details
  • Supports various access modes:
    • ReadWriteOnce: Single node read-write mounting
    • ReadOnlyMany: Multiple node read-only mounting
    • ReadWriteMany: Multiple node read-write mounting

Persistent Volume Claims (PVC)

Key Features
  • User storage requests
  • Automatically binds to suitable PVs
  • Referenced by name in pods
  • Specifies size and access mode requirements


🔄 PV Lifecycle Management

persistentVolumeReclaimPolicy

Available Policies
  • Retain: Preserves volume and data after release (default)
  • Delete: Removes volume when PVC is deleted
  • Recycle: Legacy policy, not recommended for dynamic provisioning

Lifecycle Phases

  1. Provisioning: Static or dynamic via StorageClass
  2. Binding: PVC creation and matching to available PV
  3. Using: Pod mounts and uses the volume
  4. Releasing: PVC deletion
  5. Reclaiming: Based on reclaim policy


StorageClass & CSI Implementation

The storage class provides a way to describe the “classes” of storage provided by the administrator.

It provides a standardized way to abstract the details of the underlying storage platform and dynamically provision PV.

Container storage interface (CSI) is a standard for exposing various block and file storage systems to containerized workloads in container orchestration systems (COSs), such as Kubernetes.

CSI’s goal is to provide a consistent and standardized API for storage solutions, making it easy to integrate and use storage products in a cloud native ecosystem.

StorageClass Example

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
reclaimPolicy: Delete
allowVolumeExpansion: true

PV Example

apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: standard
  awsElasticBlockStore:
    volumeID: vol-xxxxx
    fsType: ext4

PVC Example

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: example-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: standard

Pod Using PVC

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
    - name: app
      image: nginx
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: storage
  volumes:
    - name: storage
      persistentVolumeClaim:
        claimName: example-pvc


Container Storage Interface (CSI)

CSI Volume Types
  • Block Storage: For performance-critical applications
  • File Storage: For shared storage systems
  • Object Storage: For unstructured data

Available Pod Volume Types

Common Volume Types
  • hostPath: Mounts host node filesystem
  • emptyDir: Temporary directory shared with pod lifecycle
  • CSI Volumes: Provider-specific implementations



References