How to switch the default StorageClass to another one on OCP

Solution Verified - Updated -

Environment

  • Red Hat OpenShift Container Platform (RHOCP)
    • 4
  • Red Hat OpenShift Service on AWS (ROSA)
    • 4
  • Red Hat OpenShift Dedicated (OSD)
    • 4
  • Default StorageClass

Issue

  • Can the default StorageClass be changed to another one on OCP/OSD/ROSA clusters.
  • In AWS, the default StorageClass gp2 is in-tree plugin, and it will be deprecated in the future. How to change the default one to a different StorageClass?

Resolution

It's possible to switch the default StorageClass in OpenShift according to the following example procedures. The gp3-csi StorageClass is the default for clusters initially installed with 4.10 or newer versions.

Important: as explained in What happens when multiple StorageClass are marked as default in OpenShift?, if more than one StorageClass is marked as default, the behavior will be the same as if there is no default StorageClass defined, so it's needed to disable the default StorageClass before enabling the new one.

// List the storage class:
$ oc get storageclass
NAME            PROVISIONER
gp2 (default)   kubernetes.io/aws-ebs
gp2-csi         ebs.csi.aws.com
gp3-csi         ebs.csi.aws.com

// Disable "storageclass.kubernetes.io/is-default-class" annotation for the default StorageClass first:
$ oc patch storageclass gp2 -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "false"}}}'

// Make another storage class the default (in this example, gp3-csi is configured as the default):
$ oc patch storageclass gp3-csi -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "true"}}}'

Note: refer to Changing the default storage class for additional details.

Root Cause

Changing the default StorageClass is possible in OCP/OSD/ROSA clusters following the documentation.

Diagnostic Steps

List the StorageClasses:

$ oc get storageclass
NAME            PROVISIONER
gp2 (default)   kubernetes.io/aws-ebs
gp2-csi         ebs.csi.aws.com
gp3-csi         ebs.csi.aws.com

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments