KubeSphere v4 安裝指南

kubesphere發表於2024-10-17

日前,KubeSphere v4 釋出,相較於之前的版本,新版本在架構上有了顛覆性的變化。為了讓社群的各位小夥伴能夠絲滑的從舊版本過渡到新版本,我們特別推出本篇安裝指南文章,以供參考。

關於 KubeSphere v4 的介紹,請閱讀本文:KubeSphere v4 開源併發布全新可插拔架構 LuBan

需要注意的是,目前不支援從 KubeSphere 3.4.1 版本直接升級到 v4 版本,需要先解除安裝原來的版本,再安裝 v4 版本。

解除安裝 KubeSphere 3.4.1

注意:

  • 本文僅適用於測試環境,請不要直接在生產環境操作。
  • 如果需要在生產環境操作,請先在測試環境驗證透過後再進行。
  • 解除安裝為高風險操作,執行該操作前,請明確您知道自己將要做什麼。
  • 該操作會導致 KubeSphere 平臺自身無法使用,但不會影響 KubeSphere 之外即 K8s 叢集中執行的工作負載。
  • 該操作會刪除 KubeSphere 所有的元件及相關資料,您可以在此之前對資料進行備份。
  • 您可以自主選擇資料遷移工具,或等待社群的資料遷移方案,社群的遷移方案計劃透過指令碼幫助您備份平臺賬戶、許可權及相關的資料,在新版本安裝好後,可將備份資料進行匯入。
  • 如果您期望全面的資料遷移和升級,我們建議您可以考慮 KubeSphere 企業版
  • 社群鄭重提醒您,務必謹慎操作。

解綁叢集

如果開啟了多叢集,請務必在解除安裝前將叢集進行解綁。解除安裝 Host 叢集前,請確保已經沒有 Member 叢集被當前叢集納管,且角色和賬戶等資訊也會被刪除。

解除安裝 KubeSphere 3.4.1

針對待解除安裝叢集執行該指令碼。

注意:

  1. 執行該指令碼前請確保當前叢集已從 Host 叢集中解綁。
  2. 請確認即將操作的叢集是將要被解除安裝的叢集。
  3. 執行該指令碼後會將叢集中的 Prometheus 以及 Elasticsearch 刪除,存量監控和日誌資料不會被保留。
  4. 執行該指令碼後,叢集中專案閘道器仍可繼續使用,但納管至 KubeSphere 4.1.2 後需將閘道器切換到新版本閘道器,切換過程存需刪除老版本閘道器,切換為新版本閘道器。

解除安裝 DevOps 元件

helm del -n argocd devops
helm del -n kubesphere-devops-system devops

解除安裝 ServiceMesh 元件

kubectl -n istio-system delete jaeger jaeger
kubectl -n istio-system delete kiali kiali
helm del -n istio-system kiali-operator
helm del -n istio-system jaeger-operator
# 下載 istioctl
wget https://github.com/istio/istio/releases/download/1.15.6/istioctl-1.15.6-linux-amd64.tar.gz
tar -zxvf istioctl-1.15.6-linux-amd64.tar.gz
./istioctl uninstall --purge

解除安裝 ks-core、監控及日誌相關元件

#!/bin/bash
############################################################################################################
# 該指令碼用於解除安裝叢集中的 KubeSphere v3.4.1
#
# 注意: 如果為多叢集環境,執行該指令碼前請確保當前叢集已從 host 叢集中解綁
############################################################################################################
set -x
# 清除叢集所有 namespace 中的 workspace 標籤
kubectl get ns -l kubesphere.io/workspace -o name | xargs -I {} bash -c "kubectl label {} kubesphere.io/workspace- && kubectl patch {} -p '{\"metadata\":{\"ownerReferences\":[]}}' --type=merge"
# # 清除叢集所有 namespace 中的 kubefed 標籤
kubectl get ns -l kubefed.io/managed -o name | xargs -I {} bash -c "kubectl label {} kubefed.io/managed- && kubectl patch {} -p '{\"metadata\":{\"ownerReferences\":[]}}' --type=merge"
# 清除叢集中的 workspace 以及 workspacetemplate 資源
kubectl get workspacetemplate -A -o name | xargs -I {} kubectl patch {} -p '{"metadata":{"ownerReferences":[]}}' --type=merge
kubectl get workspace -A -o name | xargs -I {} kubectl patch {} -p '{"metadata":{"ownerReferences":[]}}' --type=merge
kubectl get workspacetemplate -A -o name | xargs -I {} kubectl delete {}
kubectl get workspace -A -o name | xargs -I {} kubectl delete {}
# 刪除 clusterroles
delete_cluster_roles() {
  for role in `kubectl get clusterrole -l iam.kubesphere.io/role-template -o jsonpath="{.items[*].metadata.name}"`
  do
    kubectl delete clusterrole $role 2>/dev/null
  done
}
delete_cluster_roles
# 刪除 clusterrolebindings
delete_cluster_role_bindings() {
  for rolebinding in `kubectl get clusterrolebindings -l iam.kubesphere.io/role-template -o jsonpath="{.items[*].metadata.name}"`
  do
    kubectl delete clusterrolebindings $rolebinding 2>/dev/null
  done
}
delete_cluster_role_bindings
# 刪除 validatingwebhookconfigurations
for webhook in ks-events-admission-validate users.iam.kubesphere.io network.kubesphere.io validating-webhook-configuration resourcesquotas.quota.kubesphere.io
do
  kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io $webhook 2>/dev/null
done
# 刪除 mutatingwebhookconfigurations
for webhook in ks-events-admission-mutate logsidecar-injector-admission-mutate mutating-webhook-configuration
do
  kubectl delete mutatingwebhookconfigurations.admissionregistration.k8s.io $webhook 2>/dev/null
done
# 刪除 users
for user in `kubectl get users -o jsonpath="{.items[*].metadata.name}"`
do
  kubectl patch user $user -p '{"metadata":{"finalizers":null}}' --type=merge
done
kubectl delete users --all 2>/dev/null
# 刪除 iam 資源
for resource_type in `echo globalrolebinding loginrecord rolebase workspacerole globalrole workspacerolebinding`; do
  for resource_name in `kubectl get ${resource_type}.iam.kubesphere.io -o jsonpath="{.items[*].metadata.name}"`; do
    kubectl patch ${resource_type}.iam.kubesphere.io ${resource_name} -p '{"metadata":{"finalizers":null}}' --type=merge
  done
  kubectl delete ${resource_type}.iam.kubesphere.io --all 2>/dev/null
done
# 解除安裝 ks-core
helm del -n kubesphere-system ks-core
helm del -n kubesphere-system ks-redis &> /dev/null || true
kubectl delete pvc -n kubesphere-system -l app=redis-ha --ignore-not-found || true
kubectl delete deploy -n kubesphere-system -l app.kubernetes.io/managed-by!=Helm --field-selector metadata.name=redis --ignore-not-found || true
kubectl delete svc -n kubesphere-system -l app.kubernetes.io/managed-by!=Helm --field-selector metadata.name=redis --ignore-not-found || true
kubectl delete secret -n kubesphere-system -l app.kubernetes.io/managed-by!=Helm --field-selector metadata.name=redis-secret --ignore-not-found || true
kubectl delete cm -n kubesphere-system -l app.kubernetes.io/managed-by!=Helm --field-selector metadata.name=redis-configmap --ignore-not-found || true
kubectl delete pvc -n kubesphere-system -l app.kubernetes.io/managed-by!=Helm --field-selector metadata.name=redis-pvc --ignore-not-found || true
kubectl delete deploy -n kubesphere-system --all --ignore-not-found
kubectl delete svc -n kubesphere-system --all --ignore-not-found
kubectl delete cm -n kubesphere-system --all --ignore-not-found
kubectl delete secret -n kubesphere-system --all --ignore-not-found
kubectl delete sa -n kubesphere-system --all --ignore-not-found
# 刪除 Gateway 資源
for gateway in `kubectl -n kubesphere-controls-system get gateways.gateway.kubesphere.io -o jsonpath="{.items[*].metadata.name}"`
do
  kubectl -n kubesphere-controls-system patch gateways.gateway.kubesphere.io $gateway -p '{"metadata":{"finalizers":null}}' --type=merge
done
kubectl -n kubesphere-controls-system delete gateways.gateway.kubesphere.io --all 2>/dev/null
# 刪除crd
kubectl delete crd globalrolebindings.iam.kubesphere.io
kubectl delete crd globalroles.iam.kubesphere.io
kubectl delete crd users.iam.kubesphere.io
kubectl delete crd workspacerolebindings.iam.kubesphere.io
kubectl delete crd workspaceroles.iam.kubesphere.io 
kubectl delete crd workspaces.tenant.kubesphere.io
kubectl delete crd workspacetemplates.tenant.kubesphere.io
kubectl delete crd gateways.gateway.kubesphere.io
## 解除安裝 監控元件
# 刪除 Prometheus/ALertmanager/ThanosRuler
kubectl -n kubesphere-monitoring-system delete Prometheus  k8s --ignore-not-found
kubectl -n kubesphere-monitoring-system delete secret additional-scrape-configs --ignore-not-found
kubectl -n kubesphere-monitoring-system delete serviceaccount prometheus-k8s --ignore-not-found
kubectl -n kubesphere-monitoring-system delete service prometheus-k8s --ignore-not-found
kubectl -n kubesphere-monitoring-system delete role prometheus-k8s-config --ignore-not-found
kubectl -n kubesphere-monitoring-system delete rolebinging prometheus-k8s-config --ignore-not-found
kubectl -n kubesphere-monitoring-system delete Alertmanager main --ignore-not-found
kubectl -n kubesphere-monitoring-system delete secret alertmanager-main --ignore-not-found
kubectl -n kubesphere-monitoring-system delete service alertmanager-main --ignore-not-found
kubectl -n kubesphere-monitoring-system delete ThanosRuler kubesphere --ignore-not-found
# 刪除 ServiceMonitor/PrometheusRules
kubectl -n kubesphere-monitoring-system delete ServiceMonitor alertmanager coredns etcd ks-apiserver  kube-apiserver kube-controller-manager kube-proxy kube-scheduler kube-state-metrics kubelet node-exporter  prometheus prometheus-operator  s2i-operator  thanosruler --ignore-not-found
kubectl -n kubesphere-monitoring-system delete PrometheusRule kubesphere-rules prometheus-k8s-coredns-rules prometheus-k8s-etcd-rules prometheus-k8s-rules --ignore-not-found
# 刪除 prometheus-operator
kubectl -n kubesphere-monitoring-system delete deployment prometheus-operator --ignore-not-found
kubectl -n kubesphere-monitoring-system delete service  prometheus-operator --ignore-not-found
kubectl -n kubesphere-monitoring-system delete serviceaccount prometheus-operator --ignore-not-found
# 刪除 kube-state-metrics/node-exporter
kubectl -n kubesphere-monitoring-system delete deployment kube-state-metrics --ignore-not-found
kubectl -n kubesphere-monitoring-system delete service  kube-state-metrics --ignore-not-found
kubectl -n kubesphere-monitoring-system delete serviceaccount  kube-state-metrics --ignore-not-found
kubectl -n kubesphere-monitoring-system delete daemonset node-exporter --ignore-not-found
kubectl -n kubesphere-monitoring-system delete service node-exporter --ignore-not-found
kubectl -n kubesphere-monitoring-system delete serviceaccount node-exporter --ignore-not-found
# 刪除 Clusterrole/ClusterRoleBinding
kubectl delete clusterrole kubesphere-prometheus-k8s kubesphere-kube-state-metrics kubesphere-node-exporter kubesphere-prometheus-operator
kubectl delete clusterrolebinding kubesphere-prometheus-k8s kubesphere-kube-state-metrics kubesphere-node-exporter kubesphere-prometheus-operator
# 刪除 notification-manager
helm delete notification-manager -n kubesphere-monitoring-system
# 清理 kubesphere-monitoring-system
kubectl delete deploy -n kubesphere-monitoring-system --all --ignore-not-found
# 刪除監控 crd
kubectl delete crd alertmanagerconfigs.monitoring.coreos.com
kubectl delete crd alertmanagers.monitoring.coreos.com
kubectl delete crd podmonitors.monitoring.coreos.com
kubectl delete crd probes.monitoring.coreos.com
kubectl delete crd prometheusagents.monitoring.coreos.com
kubectl delete crd prometheuses.monitoring.coreos.com
kubectl delete crd prometheusrules.monitoring.coreos.com
kubectl delete crd scrapeconfigs.monitoring.coreos.com
kubectl delete crd servicemonitors.monitoring.coreos.com
kubectl delete crd thanosrulers.monitoring.coreos.com
kubectl delete crd clusterdashboards.monitoring.kubesphere.io
kubectl delete crd dashboards.monitoring.kubesphere.io
# 刪除 metrics-server
kubectl delete apiservice v1beta1.metrics.k8s.io
kubectl -n kube-system delete deploy metrics-server
kubectl -n kube-system delete service metrics-server
kubectl delete ClusterRoleBinding system:metrics-server
kubectl delete ClusterRoleBinding metrics-server:system:auth-delegator
kubectl -n kube-system delete RoleBinding  metrics-server-auth-reader
kubectl delete ClusterRole system:metrics-server
kubectl delete ClusterRole system:aggregated-metrics-reader
kubectl -n kube-system delete ServiceAccount ServiceAccount
## 解除安裝 日誌元件
# 刪除 fluent-bit
kubectl -n kubesphere-logging-system delete fluentbitconfigs fluent-bit-config --ignore-not-found
kubectl -n kubesphere-logging-system patch fluentbit fluent-bit -p '{"metadata":{"finalizers":null}}' --type=merge
kubectl -n kubesphere-logging-system delete fluentbit fluent-bit --ignore-not-found
# 刪除 ks-logging
helm del -n kubesphere-logging-system logsidecar-injector &> /dev/null || true
# 刪除 ks-events
helm del -n kubesphere-logging-system ks-events &> /dev/null || true
# 刪除 kube-auditing
helm del -n kubesphere-logging-system kube-auditing &> /dev/null || true
# 刪除 es 
helm del -n kubesphere-logging-system elasticsearch-logging &> /dev/null || true
helm del -n kubesphere-logging-system elasticsearch-logging-curator &> /dev/null || true
# 刪除 opensearch
helm del -n kubesphere-logging-system opensearch-master &> /dev/null || true
helm del -n kubesphere-logging-system opensearch-data &> /dev/null || true
helm del -n kubesphere-logging-system opensearch-logging-curator &> /dev/null || true
# 清理 kubesphere-logging-system
kubectl delete deploy -n kubesphere-logging-system --all --ignore-not-found

檢查 Namespace 標籤

確認所有 Namespace 不包含 kubesphere.io/workspace 標籤。

kubectl get ns --show-labels

解除安裝 Kubefed(Host 叢集)

helm del -n kube-federation-system kubefed

安裝 KubeSphere 4.1.2

升級 Crd

# 下載 ks-core chart 包 
helm fetch https://charts.kubesphere.io/main/ks-core-1.1.2.tgz --untar
# 更新 crds 
kubectl apply -f ks-core/charts/ks-crds/crds/

Host 叢集安裝 ks-core

自 KubeSphere v4.1 開始,僅需在 Host 叢集部署 ks-core 即可,Member 叢集透過頁面新增(切勿在 Member 叢集再次部署 ks-core)。

# 該命令僅需在 host 叢集上執行
# 如果訪問 dockerhub 受限,在以下命令中新增 
# --set global.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks 
# --set extension.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks 
helm upgrade --install -n kubesphere-system --create-namespace ks-core https://charts.kubesphere.io/main/ks-core-1.1.2.tgz --debug --wait

新增 Member 叢集

Host 叢集部署好之後,進入工作臺點選叢集管理

點選新增叢集

填寫叢集資訊,並點選下一步

填寫 Member 叢集 Kubeconfig:

填寫叢集配置:

# 如果訪問 dockerhub 受限,此處可填,如果能夠正常訪問 dockerhub,可跳過該步驟。
global:
  imageRegistry: swr.cn-southwest-2.myhuaweicloud.com/ks

點選建立後等待 Member 叢集上的 ks-agent 建立成功。

Gateway 遷移

安裝 Gateway 元件

安裝 KubeSphere 閘道器擴充套件元件,併為需要使用閘道器的叢集安裝 Gateway 擴充套件元件 Agent。

將使用了專案閘道器的專案加入目標企業空間

執行解除安裝指令碼時,會刪除專案的企業空間關聯關係,需將使用了專案閘道器的專案重新加入新的目標企業空間中。

遷移專案閘道器到新版本

注意:該步驟會導致專案閘道器中斷,需提前考慮業務影響。

刪除待遷移專案閘道器

如需保證訪問埠不變,刪除前務必記錄對應閘道器的 Nodeport 資訊或者 LoadBalancer 資訊,以便在新建立閘道器時保留原有配置。

新建專案閘道器

透過企業空間進入到專案的專案設定中的閘道器設定。

以保留原有閘道器的 Nodeport 為例:

點選確定。

關聯應用路由至新建閘道器

待新的專案閘道器建立成功後,在閘道器頁面中點選管理->編輯,複製其中的 IngressClassName。

針對當前專案下的應用路由,點選編輯 YAML。

Spec 新增 ingressClassName: xxx,儲存。

總結

以上就是 KubeSphere v4 安裝的完整步驟,供大家參考。如果您在安裝過程中出現問題,可去論壇搜尋是否有解答,如沒有,可在論壇提問: https://ask.kubesphere.io/forum/。

KubeSphere v4 徵稿啟事:誠邀體驗並分享最佳實踐!稿件被採納者,將獲得 T 恤、帆布袋等社群禮品,優秀作者更有機會贏取 CKA 代金券大獎。投稿請微信搜尋“kubesphere”聯絡小助手小 kk。

關於 KubeSphere

KubeSphere (https://kubesphere.io)是在 Kubernetes 之上構建的開源容器平臺,提供全棧的 IT 自動化運維的能力,簡化企業的 DevOps 工作流。

KubeSphere 已被 Aqara 智慧家居、本來生活、東方通訊、微宏科技、東軟、華雲、新浪、三一重工、華夏銀行、四川航空、國藥集團、微眾銀行、紫金保險、去哪兒網、中通、中國人民銀行、中國銀行、中國人保壽險、中國太平保險、中國移動、中國聯通、中國電信、天翼雲、中移金科、Radore、ZaloPay 等海內外數萬家企業採用。

KubeSphere 提供了開發者友好的嚮導式操作介面和豐富的企業級功能,包括 Kubernetes 多雲與多叢集管理、DevOps (CI/CD)、應用生命週期管理、邊緣計算、微服務治理 (Service Mesh)、多租戶管理、可觀測性、儲存與網路管理、GPU support 等功能,幫助企業快速構建一個強大和功能豐富的容器雲平臺。

✨ GitHub:https://github.com/kubesphere
💻 官網(中國站):https://kubesphere.io/zh
🙋 論壇:https://ask.kubesphere.io/forum/
👨‍💻‍ 微信群:請搜尋新增群助手微訊號 kubesphere

相關文章