Kahibaro
Discord Login Register

StorageClasses

Role of StorageClasses in OpenShift

In OpenShift, a StorageClass describes how storage should be provisioned for PersistentVolumeClaims (PVCs). Where a PVC describes what an application needs (size, access mode), a StorageClass describes the backend, performance, and policy used to satisfy that request.

When dynamic provisioning is enabled, a StorageClass acts as the “template” for creating new PersistentVolumes (PVs) on demand.

Key points:

StorageClass Anatomy

A StorageClass is a Kubernetes resource with some OpenShift specifics. Typical fields:

Minimal example:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-ssd
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp3
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

Provisioner

The provisioner field determines which storage plugin manages underlying volumes. Common types in OpenShift:

The provisioner is usually installed and configured by an Operator; as an application developer you mostly just reference existing StorageClasses.

Parameters

parameters are key–value pairs specific to each provisioner. Examples (these vary by backend):

These parameters let cluster admins expose different storage “flavors” to users without exposing full backend detail.

Reclaim Policy

reclaimPolicy controls what happens to PVs created from this StorageClass when the PVC is deleted:

Example:

reclaimPolicy: Retain

Choosing the right reclaim policy is critical for data retention and cost management.

Allow Volume Expansion

If allowVolumeExpansion: true, PVCs bound to this StorageClass can be resized (subject to backend support and cluster configuration):

allowVolumeExpansion: true

This enables workflows like:

  1. Create 10Gi PVC.
  2. Later, edit PVC (or use oc patch) to request 20Gi.
  3. Storage is expanded, then filesystem is grown accordingly.

Without this setting (or if backend doesn’t support it), expansion is not allowed.

Volume Binding Mode

volumeBindingMode affects when PVs are provisioned and bound:

Example:

volumeBindingMode: WaitForFirstConsumer

On OpenShift in cloud environments, platform-provided StorageClasses usually default to WaitForFirstConsumer for better scheduling and fault-tolerance behavior.

Default StorageClass

One StorageClass can be flagged as the cluster-wide default. PVCs that omit storageClassName will use it automatically.

The default is annotated:

metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"

Key points:

Users can override by specifying storageClassName explicitly in their PVCs.

Example PVC using the default:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  # storageClassName omitted -> default StorageClass used

Example PVC using a specific StorageClass:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-fast
spec:
  storageClassName: fast-ssd
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

Working with StorageClasses in OpenShift

From a cluster user perspective, you typically:

From a cluster admin perspective, you:

Inspecting StorageClasses

Use oc to inspect StorageClasses:

List all StorageClasses:

oc get storageclass

Output example:

NAME                    PROVISIONER            RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
gp3-csi (default)       ebs.csi.aws.com        Delete          WaitForFirstConsumer   true                   30d
standard-nfs            nfs.csi.k8s.io         Retain          Immediate              true                   10d
fast-ssd                ebs.csi.aws.com        Delete          WaitForFirstConsumer   true                   5d

View details:

oc describe storageclass gp3-csi

This shows parameters, reclaim policy, volume binding mode, and which Operator / driver owns the class.

Creating and Modifying StorageClasses

In many OpenShift environments, StorageClasses are managed by platform or storage administrators, often via Operators. Still, the basic workflow looks like:

Create a StorageClass:

oc apply -f fast-ssd-sc.yaml

Example manifest:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-ssd
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  csi.storage.k8s.io/fstype: xfs
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

Set a StorageClass as default (admin action):

oc annotate storageclass gp3-csi storageclass.kubernetes.io/is-default-class="true" --overwrite

Remove default annotation:

oc annotate storageclass gp3-csi storageclass.kubernetes.io/is-default-class-

Modifying an existing StorageClass is possible, but you must consider:

StorageClasses and Dynamic Provisioning

StorageClasses enable dynamic provisioning: when a PVC references a StorageClass and no matching PV exists, the provisioner:

  1. Receives a request from Kubernetes for a new volume.
  2. Creates the volume in the backend according to class parameters.
  3. Registers a new PV object with a reference back to this StorageClass.
  4. Binds the PV to the PVC.

This behavior depends on:

If dynamic provisioning is configured, you do not manually create PVs; you define PVCs that point to appropriate StorageClasses.

Troubleshooting dynamic provisioning often starts with checking:

StorageClass Design Considerations

When designing or choosing StorageClasses, it helps to think in terms of “storage profiles” that map to application needs.

Common profiles:

Questions an admin typically considers:

Using StorageClasses Effectively as a Developer

As an application developer on OpenShift, you generally:

  1. Discover available StorageClasses in your cluster:
    • Use oc get storageclass.
    • Read documentation from your platform team, which usually describes when to use each class.
  2. Select a StorageClass based on:
    • Required access mode (ReadWriteOnce vs ReadWriteMany).
    • Performance needs (latency, IOPS).
    • Data criticality (do you want volumes retained on PVC deletion?).
  3. Reference it in your PVC:
    • Example for a high-performance DB volume:
   apiVersion: v1
   kind: PersistentVolumeClaim
   metadata:
     name: db-data
   spec:
     storageClassName: fast-ssd
     accessModes:
       - ReadWriteOnce
     resources:
       requests:
         storage: 100Gi
  1. Plan for resizing:
    • Check whether the StorageClass allows expansion (allowVolumeExpansion: true).
    • If yes, you can increase the requested size later; if not, you may need a migration strategy.
  2. Avoid hard-coding cluster-specific names:
    • For Helm charts or templates you plan to reuse across environments, parameterize the storageClassName so it can be overridden per cluster.

OpenShift-Specific Aspects

While StorageClasses are a Kubernetes concept, OpenShift adds some practical aspects:

Understanding how your OpenShift platform team has set up StorageClasses is essential: the same OpenShift version can look very different depending on which storage backends and Operators are installed.

Summary

In practice, effective use of StorageClasses lets OpenShift users request storage in a simple, declarative way, while keeping backend details and complexity encapsulated in the platform.

Views: 14

Comments

Please login to add a comment.

Don't have an account? Register now!