Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 37 ยท Storage and Scaling

Storage Classes and Dynamic Provisioning in OpenShift

Let OpenShift create volumes on demand: StorageClass parameters, the default class, CSI drivers, volume binding modes, snapshots, expansion and OpenShift Data Foundation.

Pre-creating volumes by hand does not scale. With dynamic provisioning, a claim names a StorageClass, a storage driver creates a matching volume on the fly, and the PV is bound automatically. Developers only request "20Gi of fast storage"; the platform decides how.

Commands and YAML are read-only examples (no cluster here); Python stand-ins model class selection and cost.

StorageClass

YAML
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-ssd
  annotations:
    storageclass.kubernetes.io/is-default-class: "false"
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  iops: "6000"
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

Key fields:

  • provisioner: the CSI driver that creates volumes (ebs.csi.aws.com, disk.csi.azure.com, pd.csi.storage.gke.io, vsphere.csi..., openshift-storage.rbd.csi.ceph.com for OpenShift Data Foundation, and so on).
  • parameters: driver-specific options such as disk type.
  • reclaimPolicy: inherited by the created PVs.
  • allowVolumeExpansion: lets claims grow.
  • volumeBindingMode: Immediate creates the volume at once; WaitForFirstConsumer waits until a pod is scheduled, so the volume lands in the same availability zone as the pod.
Terminal
oc get storageclass
oc describe storageclass fast-ssd

Installers usually create a default class (marked with (default) in the listing). A claim without storageClassName uses it. Mark or unmark a default with an annotation:

Terminal
oc patch storageclass fast-ssd -p '{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

Only one class should be the default; two defaults make claims ambiguous.

The flow

sequenceDiagram
  participant Dev as Developer
  participant API as API server
  participant CSI as CSI provisioner
  participant Cloud as Storage backend
  Dev->>API: create PVC (class fast-ssd, 20Gi)
  API->>CSI: new claim for class fast-ssd
  CSI->>Cloud: create 20Gi disk
  Cloud-->>CSI: volume id
  CSI->>API: create PV and bind to PVC
  API-->>Dev: PVC Bound

A claim triggers the driver, which creates the disk and the PV.

Choosing a class

Offer a few well-named classes so people do not guess:

Class Backend Good for
standard (default) General SSD Most workloads
fast-ssd High-IOPS SSD Databases
bulk-hdd Cheap HDD Logs, backups
shared-files Shared file system (RWX) Uploads shared by replicas
Python Stand-in: choose a StorageClass

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The prices above are made-up round numbers for the exercise, not a real price list. Your cloud bill is the authority.

Volume binding and zones

With Immediate, a disk may be created in zone a while the pod is scheduled to zone b, and the pod can never start. WaitForFirstConsumer avoids this. Prefer it for zonal block storage. Symptoms of the problem are pods stuck Pending with "volume node affinity conflict".

Snapshots and clones

CSI drivers that support it let you snapshot and clone volumes through Kubernetes objects:

YAML
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: shop-db-before-upgrade
spec:
  volumeSnapshotClassName: csi-snapclass
  source:
    persistentVolumeClaimName: shop-db-data

Restore by creating a new PVC with dataSource pointing at the snapshot:

YAML
spec:
  dataSource:
    name: shop-db-before-upgrade
    kind: VolumeSnapshot
    apiGroup: snapshot.storage.k8s.io

A snapshot is not a backup on its own: it often lives on the same storage system. Combine it with off-site backups (for example OADP, the OpenShift API for Data Protection, based on Velero).

OpenShift Data Foundation

On bare metal and many clusters, OpenShift Data Foundation (ODF), built on Ceph, supplies block (RBD), file (CephFS) and object (S3-compatible) storage from the cluster's own disks, installed as an Operator (operators). It provides ready-made classes such as ocs-storagecluster-ceph-rbd and ocs-storagecluster-cephfs, so RWX is available without an external NAS. Local disks can also be used directly through the Local Storage Operator for low-latency volumes.

Expansion check

Python Stand-in: can this claim grow?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does dynamic provisioning remove the need for?

    A CSI driver creates the volume when a claim names a StorageClass.
  2. 2. Why use volumeBindingMode: WaitForFirstConsumer?

    Delaying binding prevents zone mismatches between disk and pod.
  3. 3. A PVC omits storageClassName. What happens?

    Claims without a class use the class marked as default.
  4. 4. Is a CSI snapshot a complete backup strategy?

    Snapshots help with fast rollback but do not protect against loss of the storage system.

Summary

  • A StorageClass names a driver and options; claims reference it.
  • The default class serves claims that name none; keep exactly one.
  • WaitForFirstConsumer avoids zone mismatches; allowVolumeExpansion enables growth.
  • Snapshots and clones are CSI features; add real backups.
  • ODF provides block, file and object storage inside the cluster.

Next: Horizontal pod autoscaling