Setting the default StorageClass

This page shows how to set the default StorageClass for an GKE on-prem cluster. See also Storage.

Overview

GKE on-prem can integrate with block or file storage by using any of the following mechanisms:

When you create a cluster, GKE on-prem creates a Kubernetes StorageClass named standard. This is the default StorageClass for the cluster.

To see detailed information about the standard StorageClass, enter the following command:

kubectl --kubeconfig [CLUSTER_KUBECONFIG] get storageclass standard --output yaml

where [CLUSTER_KUBECONFIG] is the path of the kubeconfig file for your cluster.

In the output, you can see that the name of the StorageClass is standard. You can also see the storageclass.kubernetes.io/is-default-class: "true" annotation. This annotation identifies the StorageClass named standard as the default StorageClass.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
  ...
  name: standard
  ...
parameters:
  datastore: HOST2-DATASTORE2
  diskformat: thin
  fstype: ext4
provisioner: kubernetes.io/vsphere-volume
reclaimPolicy: Delete
volumeBindingMode: Immediate

Your cluster can have several StorageClass objects, but only one of them can have the storageclass.kubernetes.io/is-default-class: "true" annotation and therefore be the default StorageClass.

In the preceding output, you can also see that the provisioner is kubernetes.io/vsphere-volume. This is the provisioner that takes action when a client requests a piece of storage of class standard.

Default StorageClass

When you request storage, you can specify a StorageClass. If you do not specify a StorageClass, the default StorageClass is used. For example, suppose you create a PersistentVolumeClaim that does not specify a StorageClass. The volume controller will fulfill the claim according to the default StorageClass.

Changing the default StorageClass

As a cluster administrator, you might want to change the default storage class. Then all requests for storage that do not specify a StorageClass will be fulfilled according to the StorageClass of your choice. This section gives the steps for changing the default.

Deploy a new storage system

Deploy a new storage system and any software components for integrating the new storage mechanism with a Kubernetes cluster. For example, you might need to install a CSI driver in the cluster.

This step depends on the storage vendor you're using. For CSI drivers, vendors should provide instructions for deploying their CSI driver to a Kubernetes cluster. A CSI driver's documentation should also include the driver-specific parameters that you provide in your StorageClass, including the provisioner name.

When you create a StorageClass for your new appliance, you should name the StorageClass after its properties (such as "fast" or "highly-replicated"), rather than after the name of the specific driver or appliance behind it. This will make it easier to have consistent storage policies across clusters and environments.

Remove the default annotation from the standard StorageClass

To open the standard StorageClass manifest in a text editor, enter the following command:

kubectl --kubeconfig [CLUSTER_KUBECONFIG] edit storageclass standard

In the text editor, remove the storageclass.kubernetes.io/is-default-class: "true" annotation. Close the text editor.

To verify that the annotation was removed, enter this command:

kubectl --kubeconfig [CLUSTER_KUBECONFIG] get storageclass standard --output yaml

Create a new StorageClass

Create a manifest for a new StorageClass. Include the storageclass.kubernetes.io/is-default-class: "true" annotation. For example:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
  ...
  name: my-storage-class
  ...
parameters:
  ...
provisioner: [MY_PROVISIONER]
...

Save your manifest as a YAML file, and create the new StorageClass:

kubectl --kubeconfig [CLUSTER_KUBECONFIG] apply -f [MANIFEST_FILE]

where [MANIFEST_FILE] is the path to your new StorageClass manifest file.

What's next