文章大纲
设置默认的存储类在创建 PVC 资源的时候会方便一些,不需要手动的指定存储类的名称,当然最佳实践是要指定存储类的名称,避免因为设置默认的存储类不一致或更改了默认存储类而带来的影响。
当前 rook-ceph-block
存储类不是默认的存储类:
vagrant@master01:~$ kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 3h39m
vagrant@master01:~$
vagrant@master01:~$ kubectl describe sc rook-ceph-block
Name: rook-ceph-block
IsDefaultClass: No
......
设置默认存储类
只需要添加一个注解 storageclass.kubernetes.io/is-default-class=true
就可以了:
vagrant@master01:~$ kubectl patch sc rook-ceph-block -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
storageclass.storage.k8s.io/rook-ceph-block patched
设置好后,查看存储类会看到默认的存储类会在后面提示 default
:
vagrant@master01:~$ kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rook-ceph-block (default) rook-ceph.rbd.csi.ceph.com Delete Immediate true 3h46m
修改默认存储类
如果想修改默认的存储类,首先需要将原先默认存储类上的注解进行删除:
vagrant@master01:~$ kubectl patch sc rook-ceph-block -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
storageclass.storage.k8s.io/rook-ceph-block patched
查看是否已经取消了默认存储类:
vagrant@master01:~$ kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 3h49m
然后在按照前面的步骤设置默认的存储类即可。