您可以使用 kubesphere-delete.sh 將 KubeSphere 從您現(xiàn)有的 Kubernetes 集群中卸載。復(fù)制 GitHub 源文件并在本地機(jī)器上執(zhí)行此腳本。
警告:
卸載意味著 KubeSphere 會從您的 Kubernetes 集群中移除。此操作不可逆并且沒有任何備份,請謹(jǐn)慎操作。
參考鏈接:
https://kubesphere.com.cn/docs/installing-on-kubernetes/uninstall-kubesphere-from-k8s/
function delete_sure
(){cat << eof
$(echo -e "\033[1;36mNote:\033[0m")Delete the KubeSphere cluster, including the module kubesphere-system kubesphere-devops-system kubesphere-monitoring-system kubesphere-logging-system openpitrix-system.
eofread -p
"Please reconfirm that you want to delete the KubeSphere cluster. (yes/no) " ans
while [[ "x"$ans != "xyes" && "x"$ans != "xno" ]]; doread -p
"Please reconfirm that you want to delete the KubeSphere cluster. (yes/no) " ans
doneif [[ "x"$ans == "xno" ]]; thenexit
fi
}delete_sure
kubectl delete deploy ks-installer -n kubesphere-system 2
>/dev/null
for namespaces
in kubesphere-system kubesphere-devops-system kubesphere-monitoring-system kubesphere-logging-system openpitrix-system
dohelm list -n
$namespaces | grep -v NAME
| awk '{print $1}' | sort -u
| xargs -r -L1 helm uninstall -n
$namespaces 2
>/dev/null
done
kubectl get cc -n kubesphere-system ks-installer -o jsonpath
="{.status.multicluster}" | grep enable
if [[ $? -eq 0
]]; thenhelm uninstall -n kube-federation-system kubefed 2
>/dev/null
fihelm uninstall -n kube-system snapshot-controller 2
>/dev/null
kubectl delete deployment -n kubesphere-system
`kubectl get deployment -n kubesphere-system -o jsonpath="{.items[*].metadata.name}"` 2
>/dev/null
kubectl delete prometheus -n kubesphere-monitoring-system k8s 2
>/dev/null
kubectl delete statefulset -n kubesphere-monitoring-system
`kubectl get statefulset -n kubesphere-monitoring-system -o jsonpath="{.items[*].metadata.name}"` 2
>/dev/null
kubectl --no-headers
=true get pvc -n kubesphere-monitoring-system -o custom-columns
=:metadata.namespace,:metadata.name
| grep -E kubesphere-monitoring-system
| xargs -n2 kubectl delete pvc -n 2
>/dev/null
pvcs
="kubesphere-system|openpitrix-system|kubesphere-devops-system|kubesphere-logging-system"
kubectl --no-headers
=true get pvc --all-namespaces -o custom-columns
=:metadata.namespace,:metadata.name
| grep -E
$pvcs | xargs -n2 kubectl delete pvc -n 2
>/dev/null
delete_role_bindings
() {for rolebinding
in `kubectl -n $1 get rolebindings -l iam.kubesphere.io/user-ref -o jsonpath="{.items[*].metadata.name}"`dokubectl -n
$1 delete rolebinding
$rolebinding 2
>/dev/null
done
}
delete_roles
() {kubectl -n
$1 delete role admin 2
>/dev/nullkubectl -n
$1 delete role operator 2
>/dev/nullkubectl -n
$1 delete role viewer 2
>/dev/null
for role
in `kubectl -n $1 get roles -l iam.kubesphere.io/role-template -o jsonpath="{.items[*].metadata.name}"`dokubectl -n
$1 delete role
$role 2
>/dev/null
done
}
for ns
in `kubectl get ns -o jsonpath="{.items[*].metadata.name}"`
dokubectl label ns
$ns kubesphere.io/workspace-kubectl label ns
$ns kubesphere.io/namespace-kubectl patch ns
$ns -p
'{"metadata":{"finalizers":null,"ownerReferences":null}}'delete_role_bindings
$nsdelete_roles
$ns
done
for cluster
in `kubectl get clusters -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch cluster
$cluster -p
'{"metadata":{"finalizers":null}}' --type
=merge
done
kubectl delete clusters --all 2
>/dev/null
for ws
in `kubectl get workspaces -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch workspace
$ws -p
'{"metadata":{"finalizers":null}}' --type
=merge
done
kubectl delete workspaces --all 2
>/dev/null
for devopsproject
in `kubectl get devopsprojects -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch devopsprojects
$devopsproject -p
'{"metadata":{"finalizers":null}}' --type
=merge
donefor pip
in `kubectl get pipeline -A -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch pipeline
$pip -n
`kubectl get pipeline -A | grep $pip | awk '{print $1}'` -p
'{"metadata":{"finalizers":null}}' --type
=merge
donefor s2ibinaries
in `kubectl get s2ibinaries -A -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch s2ibinaries
$s2ibinaries -n
`kubectl get s2ibinaries -A | grep $s2ibinaries | awk '{print $1}'` -p
'{"metadata":{"finalizers":null}}' --type
=merge
donefor s2ibuilders
in `kubectl get s2ibuilders -A -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch s2ibuilders
$s2ibuilders -n
`kubectl get s2ibuilders -A | grep $s2ibuilders | awk '{print $1}'` -p
'{"metadata":{"finalizers":null}}' --type
=merge
donefor s2ibuildertemplates
in `kubectl get s2ibuildertemplates -A -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch s2ibuildertemplates
$s2ibuildertemplates -n
`kubectl get s2ibuildertemplates -A | grep $s2ibuildertemplates | awk '{print $1}'` -p
'{"metadata":{"finalizers":null}}' --type
=merge
donefor s2iruns
in `kubectl get s2iruns -A -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch s2iruns
$s2iruns -n
`kubectl get s2iruns -A | grep $s2iruns | awk '{print $1}'` -p
'{"metadata":{"finalizers":null}}' --type
=merge
donekubectl delete devopsprojects --all 2
>/dev/null
for webhook
in ks-events-admission-validate users.iam.kubesphere.io network.kubesphere.io validating-webhook-configuration
dokubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io
$webhook 2
>/dev/null
done
for webhook
in ks-events-admission-mutate logsidecar-injector-admission-mutate mutating-webhook-configuration
dokubectl delete mutatingwebhookconfigurations.admissionregistration.k8s.io
$webhook 2
>/dev/null
done
for user
in `kubectl get users -o jsonpath="{.items[*].metadata.name}"`
dokubectl patch user
$user -p
'{"metadata":{"finalizers":null}}' --type
=merge
done
kubectl delete
users --all 2
>/dev/null
for crd
in `kubectl get crds -o jsonpath="{.items[*].metadata.name}"`
doif [[ $crd == *kubesphere.io
]]; then kubectl delete crd
$crd 2
>/dev/null
; fi
done
for ns
in kubesphere-alerting-system kubesphere-controls-system kubesphere-devops-system kubesphere-logging-system kubesphere-monitoring-system openpitrix-system kubesphere-system
dokubectl delete ns
$ns 2
>/dev/null
done
總結(jié)
以上是生活随笔為你收集整理的从 k8s 上卸载 KubeSphere的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。