1、场景
在部署kubesphere3.3版本时其中有一个项失败;需要默认的sc
TASK [preinstall : KubeSphere | Stopping if default StorageClass was not found] ***
fatal: [localhost]: FAILED! => {
"assertion": ""(default)" in default_storage_class_check.stdout",
"changed": false,
"evaluated_to": false,
"msg": "Default StorageClass was not found !"
}
排查发现自己的sc已经创建但是不是默认的,默认的一般后面都带有 (default) 标识
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
local (default) openebs.io/local Delete WaitForFirstConsumer false 15h
managed-nfs-storage k8s-sigs.io/nfs-subdir-external-provisioner Delete Immediate false 22d
这里我的刚开始没有带默认标识,后面修改后的
默认 StorageClass 的注解 storageclass.kubernetes.io/is-default-class 设置为 true
注解的其它任意值或者缺省值将被解释为 false。
要标记一个 StorageClass 为非默认的,你需要改变它的值为 false:
2、修改sc为默认标识
kubectl patch sc local -p '{"metadata": {"annotations": {"storageclass.beta.kubernetes.io/is-default-class": "true"}}}'
其中local为我的sc名称
或者在创建class时添加注解:
metadata:
annotations:
storageclass.beta.kubernetes.io/is-default-class: "true"
3、创建local 的sc
cat >> default-storage-class.yaml <<-EOF
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local
annotations:
cas.openebs.io/config: |
- name: StorageType
value: "hostpath"
- name: BasePath
value: "/var/openebs/local/"
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"cas.openebs.io/config":"-
name: StorageType\n value: \"hostpath\"\n- name: BasePath\n value:
\"/var/openebs/local/\"\n","openebs.io/cas-type":"local","storageclass.beta.kubernetes.io/is-default-class":"true","storageclass.kubesphere.io/supported-access-modes":"[\"ReadWriteOnce\"]"},"name":"local"},"provisioner":"openebs.io/local","reclaimPolicy":"Delete","volumeBindingMode":"WaitForFirstConsumer"}
openebs.io/cas-type: local
storageclass.beta.kubernetes.io/is-default-class: 'true'
storageclass.kubesphere.io/supported-access-modes: '["ReadWriteOnce"]'
provisioner: openebs.io/local
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
EOF
kubectl apply -f default-storage-class.yaml
参考:
https://blog.csdn.net/qq_31977125/article/details/121243097
https://kubernetes.io/zh-cn/docs/tasks/administer-cluster/change-default-storage-class/