KAHIBARO Bookshelves
Discord Login Register

9.4. 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:

  • Each StorageClass usually maps to a specific storage backend or profile (e.g., fast SSD, standard HDD, NFS, cloud block storage).
  • A cluster can have multiple StorageClasses for different performance, availability, or cost characteristics.
  • One StorageClass can be marked as the default — PVCs that don’t specify a storageClassName will use it.

StorageClass Anatomy

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

  • provisioner: the CSI or in-tree plugin that creates volumes.
  • parameters: backend-specific settings (e.g., volume type, IOPS, replication).
  • reclaimPolicy: what happens to a PV after its PVC is deleted.
  • allowVolumeExpansion: whether PVCs using this class can be expanded.
  • volumeBindingMode: when volume provisioning and binding occur.

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:

  • CSI drivers (preferred in modern clusters), e.g.:
    • ebs.csi.aws.com (AWS EBS)
    • pd.csi.storage.gke.io / pd.csi.cloud.google.com (GCE PD)
    • disk.csi.azure.com (Azure Disk)
    • Vendor CSI drivers (NetApp, Dell, Ceph, etc.)
  • Legacy in-tree provisioners (deprecated in newer Kubernetes versions, but still seen in older clusters).

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):

  • Cloud block storage:
    • type: performance class (e.g., gp3, io1, premium-lrs)
    • iopsPerGB, throughput: performance settings
    • encrypted, kmsKeyId: encryption settings
  • File storage:
    • nfsServer, nfsPath for NFS-based drivers
  • Ceph / distributed storage:
    • pool: storage pool name
    • replication: replication factor
    • csi.storage.k8s.io/fstype: filesystem type (ext4, xfs, etc.)

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:

  • Delete:
    • Underlying storage is deleted when the PVC is deleted.
    • Common in cloud / ephemeral environments.
  • Retain:
    • PV and underlying storage are kept; data remains.
    • Admin intervention is required to reuse or manually remove it.
    • Useful when you must avoid accidental data loss.

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:

  • Immediate (default behavior in classic Kubernetes):
    • Volume is created and bound as soon as PVC is created.
    • Can cause suboptimal or impossible scheduling in multi-zone environments (volume may get created in a zone with no suitable nodes).
  • WaitForFirstConsumer:
    • Volume is not created until a Pod using the PVC is scheduled.
    • Scheduler considers node location (zone, region, topology, etc.) before provisioning the volume.
    • Strongly recommended for multi-zone / multi-region clusters.

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:

  • Only one StorageClass should be default; if multiple are annotated, behavior is implementation-specific and should be avoided.
  • Cluster admins should pick a sensible default that is:
    • Generally available across nodes
    • Reasonable in performance and cost
    • Appropriate for generic workloads

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:

  • List available StorageClasses to understand your options.
  • Choose a StorageClass based on performance, access, and cost requirements.
  • Reference the chosen StorageClass in your PVC.

From a cluster admin perspective, you:

  • Create and manage StorageClasses to expose appropriate storage profiles.
  • Integrate with storage backends and CSI drivers via Operators.
  • Control policies like retention, expansion, and binding behavior.

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:

  • Changes affect new PVs created after the change; existing PVs are not retroactively adjusted.
  • Some fields (like provisioner) should not be changed on a class that is already in use.

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:

  • StorageClass existence and correctness.
  • The CSI driver or provisioner being installed and healthy.
  • Cluster permissions and infrastructure access.

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:

  • Events on the PVC (oc describe pvc ...).
  • Status and logs of the CSI driver Pods.
  • The configuration of the StorageClass (typos in parameters, incorrect provisioner name, etc.).

StorageClass Design Considerations

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

Common profiles:

  • General-purpose:
    • Balanced cost/performance.
    • Often the default StorageClass.
  • High-performance:
    • SSD-based, higher IOPS and throughput, possibly with higher cost.
    • For databases, latency-sensitive workloads.
  • Capacity/archival:
    • Larger, cheaper, slower.
    • For logs, backups, or cold data.
  • File vs block:
    • Block storage for single-node attachment (ReadWriteOnce).
    • Shared file storage for multi-node access (ReadWriteMany), e.g., NFS or distributed file systems.

Questions an admin typically considers:

  • Do different teams/apps need different performance tiers?
  • How should data be retained: Delete or Retain?
  • Do we require volume expansion by developers?
  • How does topology (zones, regions) impact volumeBindingMode?
  • Which StorageClasses should be visible to which users (via RBAC and project policies)?

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:

  • Many StorageClasses are created and managed by Operators:
    • For example, an Operator for a storage product may create multiple StorageClasses (gold, silver, bronze).
  • OpenShift’s UI integrates StorageClasses:
    • The web console shows available classes when you create a PVC.
    • It often includes documentation links or labels that indicate intended use.
  • Security and multi-tenancy:
    • Not all StorageClasses may be intended for all projects; platform teams may use RBAC or admission controls to limit who can use certain classes (for cost or compliance reasons).

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

  • StorageClasses define how storage is provisioned: which backend, policy, and performance profile.
  • They are central to dynamic provisioning of PVs from PVCs.
  • Key fields include provisioner, parameters, reclaimPolicy, allowVolumeExpansion, and volumeBindingMode.
  • One StorageClass can be marked as default; PVCs without storageClassName will use it.
  • Developers choose StorageClasses based on workload requirements; admins design and manage classes to align with infrastructure capabilities and organizational policies.

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: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

Where to Move

Move chapter:

  • ☰ 1. Course Overview
    • ☰ 1.1. What is OpenShift
      • ☰ 1.2. Why OpenShift is used in modern IT and cloud environments
        • ☰ 1.3. OpenShift vs Kubernetes
          • ☰ 1.4. Typical OpenShift use cases
            • ☰ 1.5. Structure and goals of the course
            • ☰ 2. Containers and Cloud-Native Fundamentals
              • ☰ 2.1. What is a container
                • ☰ 2.2. Containers vs virtual machines
                  • ☰ 2.3. Introduction to Docker and container images
                    • ☰ 2.4. Container registries
                      • ☰ 2.5. Basics of cloud-native applications
                      • ☰ 3. Kubernetes Fundamentals
                        • ☰ 3.1. What is Kubernetes
                          • ☰ 3.2. Kubernetes architecture
                            • ☰ 3.3. Control plane components
                              • ☰ 3.4. Worker node components
                                • ☰ 3.5. Kubernetes objects and resources
                                  • ☰ 3.6. Declarative configuration model
                                  • ☰ 4. OpenShift Architecture
                                    • ☰ 4.1. Overview of OpenShift architecture
                                      • ☰ 4.2. Control plane in OpenShift
                                        • ☰ 4.3. Nodes and machine roles
                                          • ☰ 4.4. OpenShift Operators
                                            • ☰ 4.5. OpenShift networking model
                                              • ☰ 4.6. OpenShift storage model
                                              • ☰ 5. OpenShift Installation and Deployment Models
                                                • ☰ 5.1. OpenShift deployment options
                                                  • ☰ 5.2. Installer-Provisioned Infrastructure
                                                    • ☰ 5.3. User-Provisioned Infrastructure
                                                      • ☰ 5.4. Managed OpenShift services
                                                        • ☰ 5.5. Single-node OpenShift
                                                          • ☰ 5.6. Cluster lifecycle management
                                                          • ☰ 6. Accessing and Using OpenShift
                                                            • ☰ 6.1. OpenShift web console
                                                              • ☰ 6.2. OpenShift CLI (oc)
                                                                • ☰ 6.3. Authentication and authorization
                                                                  • ☰ 6.4. Projects and namespaces
                                                                    • ☰ 6.5. Resource quotas and limits
                                                                    • ☰ 7. Building and Deploying Applications
                                                                      • ☰ 7.1. Application deployment concepts
                                                                        • ☰ 7.2. Source-to-Image (S2I)
                                                                          • ☰ 7.3. Container-based deployments
                                                                            • ☰ 7.4. DeploymentConfigs and Deployments
                                                                              • ☰ 7.5. Rolling updates and rollbacks
                                                                              • ☰ 8. Networking in OpenShift
                                                                                • ☰ 8.1. Services and service discovery
                                                                                  • ☰ 8.2. Routes and ingress
                                                                                    • ☰ 8.3. Network policies
                                                                                      • ☰ 8.4. Load balancing
                                                                                        • ☰ 8.5. External access to applications
                                                                                        • ☰ 9. Storage in OpenShift
                                                                                          • ☰ 9.1. Persistent storage concepts
                                                                                            • ☰ 9.2. Persistent Volumes
                                                                                              • ☰ 9.3. Persistent Volume Claims
                                                                                                • ☰ 9.4. StorageClasses
                                                                                                  • ☰ 9.5. Dynamic provisioning
                                                                                                    • ☰ 9.6. Stateful applications
                                                                                                    • ☰ 10. Configuration and Secrets Management
                                                                                                      • ☰ 10.1. ConfigMaps
                                                                                                        • ☰ 10.2. Secrets
                                                                                                          • ☰ 10.3. Environment variables
                                                                                                            • ☰ 10.4. Managing sensitive data
                                                                                                              • ☰ 10.5. Best practices for configuration
                                                                                                              • ☰ 11. Scaling and High Availability
                                                                                                                • ☰ 11.1. Horizontal pod autoscaling
                                                                                                                  • ☰ 11.2. Vertical scaling
                                                                                                                    • ☰ 11.3. Self-healing and pod restarts
                                                                                                                      • ☰ 11.4. High availability concepts
                                                                                                                        • ☰ 11.5. Multi-zone and multi-region clusters
                                                                                                                        • ☰ 12. Monitoring, Logging, and Observability
                                                                                                                          • ☰ 12.1. Built-in monitoring stack
                                                                                                                            • ☰ 12.2. Metrics and alerts
                                                                                                                              • ☰ 12.3. Logging architecture
                                                                                                                                • ☰ 12.4. Distributed tracing
                                                                                                                                  • ☰ 12.5. Troubleshooting applications
                                                                                                                                  • ☰ 13. Security in OpenShift
                                                                                                                                    • ☰ 13.1. Security model overview
                                                                                                                                      • ☰ 13.2. Role-Based Access Control
                                                                                                                                        • ☰ 13.3. Security Context Constraints
                                                                                                                                          • ☰ 13.4. Image security and scanning
                                                                                                                                            • ☰ 13.5. Network security
                                                                                                                                              • ☰ 13.6. Compliance and auditing
                                                                                                                                              • ☰ 14. CI/CD and DevOps with OpenShift
                                                                                                                                                • ☰ 14.1. DevOps concepts
                                                                                                                                                  • ☰ 14.2. CI/CD pipelines overview
                                                                                                                                                    • ☰ 14.3. OpenShift Pipelines (Tekton)
                                                                                                                                                      • ☰ 14.4. GitOps with Argo CD
                                                                                                                                                        • ☰ 14.5. Integrating OpenShift with external CI tools
                                                                                                                                                        • ☰ 15. Operators and Platform Services
                                                                                                                                                          • ☰ 15.1. What are Operators
                                                                                                                                                            • ☰ 15.2. Operator Lifecycle Manager
                                                                                                                                                              • ☰ 15.3. Installing and managing Operators
                                                                                                                                                                • ☰ 15.4. Common platform Operators
                                                                                                                                                                  • ☰ 15.5. Custom Operators
                                                                                                                                                                  • ☰ 16. Upgrades, Maintenance, and Operations
                                                                                                                                                                    • ☰ 16.1. OpenShift upgrade process
                                                                                                                                                                      • ☰ 16.2. Backup and restore
                                                                                                                                                                        • ☰ 16.3. Node maintenance
                                                                                                                                                                          • ☰ 16.4. Cluster troubleshooting
                                                                                                                                                                            • ☰ 16.5. Capacity planning
                                                                                                                                                                            • ☰ 17. OpenShift on HPC and Specialized Workloads
                                                                                                                                                                              • ☰ 17.1. Running batch workloads on OpenShift
                                                                                                                                                                                • ☰ 17.2. OpenShift and GPUs
                                                                                                                                                                                  • ☰ 17.3. MPI and parallel workloads in containers
                                                                                                                                                                                    • ☰ 17.4. Hybrid HPC and cloud workflows
                                                                                                                                                                                    • ☰ 18. OpenShift in Practice
                                                                                                                                                                                      • ☰ 18.1. Typical OpenShift workflows
                                                                                                                                                                                        • ☰ 18.2. Development to production lifecycle
                                                                                                                                                                                          • ☰ 18.3. Case studies from industry
                                                                                                                                                                                            • ☰ 18.4. Common pitfalls and best practices
                                                                                                                                                                                            • ☰ 19. Future Directions and Ecosystem
                                                                                                                                                                                              • ☰ 19.1. Kubernetes ecosystem overview
                                                                                                                                                                                                • ☰ 19.2. OpenShift roadmap
                                                                                                                                                                                                  • ☰ 19.3. Serverless and event-driven workloads
                                                                                                                                                                                                    • ☰ 19.4. AI and data platforms on OpenShift
                                                                                                                                                                                                    • ☰ 20. Final Project and Hands-On Exercises
                                                                                                                                                                                                      • ☰ 20.1. Deploying a containerized application
                                                                                                                                                                                                        • ☰ 20.2. Implementing CI/CD with OpenShift
                                                                                                                                                                                                          • ☰ 20.3. Securing and scaling an application
                                                                                                                                                                                                            • ☰ 20.4. Monitoring and troubleshooting report