Change the default StorageClass
This page shows how to change the default Storage Class that is used toprovision volumes for PersistentVolumeClaims that have no special requirements.
Before you begin
You need to have a Kubernetes cluster, and the kubectl command-line tool mustbe configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as control plane hosts. If you do not already have acluster, you can create one by usingminikubeor you can use one of these Kubernetes playgrounds:
To check the version, enterkubectl version.
Why change the default storage class?
Depending on the installation method, your Kubernetes cluster may be deployed withan existing StorageClass that is marked as default. This default StorageClassis then used to dynamically provision storage for PersistentVolumeClaimsthat do not require any specific storage class. SeePersistentVolumeClaim documentationfor details.
The pre-installed default StorageClass may not fit well with your expected workload;for example, it might provision storage that is too expensive. If this is the case,you can either change the default StorageClass or disable it completely to avoiddynamic provisioning of storage.
Deleting the default StorageClass may not work, as it may be re-createdautomatically by the addon manager running in your cluster. Please consult the docs for your installationfor details about addon manager and how to disable individual addons.
Changing the default StorageClass
List the StorageClasses in your cluster:
kubectl get storageclassThe output is similar to this:
NAME PROVISIONER AGEstandard(default) kubernetes.io/gce-pd 1dgold kubernetes.io/gce-pd 1dThe default StorageClass is marked by
(default).Mark the default StorageClass as non-default:
The default StorageClass has an annotation
storageclass.kubernetes.io/is-default-classset totrue. Any other valueor absence of the annotation is interpreted asfalse.To mark a StorageClass as non-default, you need to change its value to
false:kubectl patch storageclass standard -p'{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'where
standardis the name of your chosen StorageClass.Mark a StorageClass as default:
Similar to the previous step, you need to add/set the annotation
storageclass.kubernetes.io/is-default-class=true.kubectl patch storageclass gold -p'{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'Please note you can have multiple
StorageClassmarked as default. If morethan oneStorageClassis marked as default, aPersistentVolumeClaimwithoutan explicitly definedstorageClassNamewill be created using the most recentlycreated defaultStorageClass.When aPersistentVolumeClaimis created with a specifiedvolumeName, it remainsin a pending state if the static volume'sstorageClassNamedoes not match theStorageClasson thePersistentVolumeClaim.Verify that your chosen StorageClass is default:
kubectl get storageclassThe output is similar to this:
NAME PROVISIONER AGEstandard kubernetes.io/gce-pd 1dgold(default) kubernetes.io/gce-pd 1d
What's next
- Learn more aboutPersistentVolumes.