Cloud Native 4 min read

How to Set and Verify the Default StorageClass in Kubernetes

This guide explains why a default StorageClass matters in Kubernetes, shows how to set one as default, verify it, and create a PVC that automatically uses the default class, complete with command‑line examples and tips.

Linux Ops Smart Journey
Linux Ops Smart Journey
Linux Ops Smart Journey
How to Set and Verify the Default StorageClass in Kubernetes

Why Default StorageClass Matters

When a PersistentVolumeClaim (PVC) is created without specifying a

storageClassName

, Kubernetes automatically uses the default StorageClass to provision a volume, simplifying operations and ensuring consistency.

Set a Default StorageClass

Run the following command, replacing

<your-class-name>

with the desired StorageClass name:

<code>kubectl patch storageclass ceph-rbd-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
</code>

Tip: Replace

&lt;your-class-name&gt;

with the actual StorageClass name.

Verify the Default StorageClass

List the StorageClass to see which one is marked as default (indicated by

(default)

).

<code>kubectl get sc ceph-rbd-storage
NAME               PROVISIONER        RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
ceph-rbd-storage   (default) rbd.csi.ceph.com   Retain   Immediate   true   4d11h
</code>

Tip: The presence of

(default)

after the StorageClass name confirms it is the default.

Create and Test a PVC Using the Default StorageClass

1. Create a PVC without specifying a

storageClassName

:

<code>cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-default-sc
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
EOF
</code>

2. Verify that the PVC is bound to the default StorageClass:

<code>kubectl get pvc test-default-sc
NAME               STATUS   VOLUME                                 CAPACITY   ACCESS MODES   STORAGECLASS       AGE
test-default-sc    Bound    pvc-1423da19-d267-49cc-92cc-7117a7f9a956   10Gi      RWO            ceph-rbd-storage   6s
</code>

Reference Articles

https://kubernetes.io/zh-cn/docs/concepts/storage/storage-classes/#default-storageclass

https://kubernetes.io/zh-cn/docs/tasks/administer-cluster/change-default-storage-class/

Conclusion

The default StorageClass is a key component of Kubernetes storage management; configuring it properly can greatly improve efficiency and flexibility.

Cloud NativeKubernetesDevOpsPersistentVolumeStorageClass
Linux Ops Smart Journey
Written by

Linux Ops Smart Journey

The operations journey never stops—pursuing excellence endlessly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.