1. 程式人生 > 其它 >k8s 叢集中安裝 kubesphere v3.1.1

k8s 叢集中安裝 kubesphere v3.1.1

k8s 叢集中安裝 kubesphere v3.1.1

目錄

kubesphere 可以直接在裸機 linux 安裝,也可在已經存在的 k8s 叢集中安裝,本文只介紹在存在的 k8s 叢集中安裝 kubesphere 。

什麼是 KubeSphere

KubeSphere 是在 Kubernetes 之上構建的面向雲原生應用的分散式作業系統,完全開源,支援多雲與多叢集管理,提供全棧的 IT 自動化運維能力,簡化企業的 DevOps 工作流。它的架構可以非常方便地使第三方應用與雲原生生態元件進行即插即用 (plug-and-play) 的整合。

作為全棧的多租戶容器平臺,KubeSphere 提供了運維友好的嚮導式操作介面,幫助企業快速構建一個強大和功能豐富的容器雲平臺。KubeSphere 為使用者提供構建企業級 Kubernetes 環境所需的多項功能,例如多雲與多叢集管理、Kubernetes 資源管理、DevOps、應用生命週期管理、微服務治理(服務網格)、日誌查詢與收集、服務與網路、多租戶管理、監控告警、事件與審計查詢、儲存管理、訪問許可權控制、GPU 支援、網路策略、映象倉庫管理以及安全管理等。

KubeSphere 還開源了 KubeKey 幫助企業一鍵在公有云或資料中心快速搭建 Kubernetes 叢集,提供單節點、多節點、叢集外掛安裝,以及叢集升級與運維。

開發運維友好

KubeSphere 為使用者遮蔽了基礎設施底層複雜的技術細節,幫助企業在各類基礎設施之上無縫地部署、更新、遷移和管理現有的容器化應用。通過這種方式,KubeSphere 使開發人員能夠專注於應用程式開發,使運維團隊能夠通過企業級可觀測性功能和故障排除機制、統一監控和日誌查詢、儲存和網路管理,以及易用的 CI/CD 流水線等來加快 DevOps 自動化工作流程和交付流程等。

支援在任意平臺執行 KubeSphere

作為一個靈活的輕量級容器 PaaS 平臺,KubeSphere 對不同雲生態系統的支援非常友好,因為它對原生 Kubernetes 本身沒有任何的侵入 (Hack)。換句話說,KubeSphere 可以部署並執行在任何基礎架構以及所有版本相容的 Kubernetes 叢集之上,包括虛擬機器、物理機、資料中心、公有云和混合雲等。

您可以選擇在公有云和託管 Kubernetes 叢集(例如阿里雲、AWS、青雲QingCloud、騰訊雲、華為雲等)上安裝 KubeSphere,還可以匯入和納管已有的 Kubernetes 叢集。

KubeSphere 可以在不修改使用者當前的資源或資產、不影響其業務的情況下部署在現有的 Kubernetes 平臺上。有關更多資訊,請參見在 Linux 上安裝和在 Kubernetes 上安裝。

完全開源

藉助開源的模式,KubeSphere 社群驅動著開發工作以開放的方式進行。KubeSphere 100% 開源免費,已大規模服務於社群使用者,廣泛地應用在以 Docker 和 Kubernetes 為中心的開發、測試及生產環境中,大量服務平穩地執行在 KubeSphere 之上。您可在 GitHub 上找到所有原始碼、文件和討論,所有主要的開源專案介紹可以在開源專案列表中找到。

雲原生 Landscape

KubeSphere 是 CNCF 基金會成員並且通過了 Kubernetes 一致性認證,進一步豐富了 CNCF 雲原生的生態。

前置條件

叢集中有預設 storage class,可以使用本地儲存,NFS,CEPH,glusterfs 等

本地儲存 yaml 參考:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

配置為預設 sc

kubectl patch storageclass local-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
  • storageclass.kubernetes.io/is-default-class 設定為 false 即可去除預設

檢視已經執行ok

kubectl get sc

建立 docker hub 映象倉庫

可以使用 Harbor 或者其他任意私有映象倉庫。本教程以 Docker 倉庫作為示例,並使用自簽名證書(如果已有私有映象倉庫,可以跳過這一步)。

建立自簽證書

執行命令

openssl req \
-newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key \
-x509 -days 36500 -out certs/domain.crt

當生成自己的證書時,請確保在欄位 Common Name 中指定一個域名。例如,本示例中該欄位被指定為 dockerhub.leffss.local

啟動 docker 倉庫

執行以下命令啟動 Docker 倉庫:

docker run -d \
  --restart=always \
  --name registry \
  -v "$(pwd)"/certs:/certs \
  -v /mnt/registry:/var/lib/registry \
  -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
  -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
  -p 443:443 \
  registry:2
  • registry:2 部署的倉庫可以新增 http 驗證(使用 docker login 登入)

備註:Docker 使用 /var/lib/docker 作為預設路徑來儲存所有 Docker 相關檔案(包括映象)。建議您新增附加儲存卷,分別給 /var/lib/docker 和 /mnt/registry(對映給 docker hub) 掛載至少 100G。

配置倉庫

在需要訪問倉庫的 docker 主機 /etc/hosts 新增一條記錄:

# docker registry
192.168.223.151 dockerhub.leffss.local

執行:

mkdir -p  /etc/docker/certs.d/dockerhub.leffss.local
mv domain.crt ca.crt
mv ca.crt /etc/docker/certs.d/dockerhub.leffss.local/
  • 目錄和 docker hub 的域名保持一致
  • domain.crt 為前面搭建倉庫時生成的證書檔案
  • 如果是容器執行時使用的 containerd ,配置方法應該不一樣,這裡沒作研究。

測試

docker pull busybox:1.28.3
docker tag busybox:1.28.3 dockerhub.leffss.local/busybox:1.28.3
docker push dockerhub.leffss.local/busybox:1.28.3

docker rmi busybox:1.28.3
docker rmi dockerhub.leffss.local/busybox:1.28.3

docker pull dockerhub.leffss.local/busybox:1.28.3
  • 如果 hub 正常,整個過程應該不會報錯

準備安裝映象

當在離線環境中安裝 KubeSphere 時,需要事先準備一個包含所有必需映象的映象包。

下載映象清單檔案 images-list.txt

curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/images-list.txt

該檔案根據不同的模組列出了 ##+modulename 下的映象。可以按照相同的規則把自己的映象新增到這個檔案中。

下載 offline-installation-tool.sh

curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/offline-installation-tool.sh

根據 images-list.txt 下載映象

mkdir kubesphere-images
sh offline-installation-tool.sh -s -l images-list.txt -d ./kubesphere-images

可以根據需要選擇拉取的映象。例如,如果已經有一個 Kubernetes 叢集了,則可以在 images-list.text 中刪除 ##k8s-images 和在它下面的相關映象。

推送映象至私有倉庫

將打包的映象檔案傳輸至本地倉庫

./offline-installation-tool.sh -l images-list.txt -d ./kubesphere-images -r dockerhub.leffss.local
  • 命令中的域名是 dockerhub.leffss.local。請確保使用自己倉庫的地址。

下載部署檔案

下載 cluster-configuration.yaml 和 kubesphere-installer.yaml

curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml
curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml

編輯 cluster-configuration.yaml 新增私有映象倉庫

...
spec:
  persistence:
    storageClass: ""        # If there is no default StorageClass in your cluster, you need to specify an existing StorageClass here.
  authentication:
    jwtSecret: ""           # Keep the jwtSecret consistent with the Host Cluster. Retrieve the jwtSecret by executing "kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v "apiVersion" | grep jwtSecret" on the Host Cluster.
  local_registry: dockerhub.leffss.local        # Add your private registry address if it is needed.
...

可以在該 YAML 檔案中啟用可插拔元件,體驗 KubeSphere 的更多功能。有關詳情,請參考後面啟用可插拔元件。預設最小化安裝。可以後面修改開啟元件後,使用 kubectl apply -f cluster-configuration.yaml 生效。

編輯 kubesphere-installer.yaml 將 ks-installer 替換為本地倉庫的地址

    spec:
      serviceAccountName: ks-installer
      containers:
      - name: installer
        image: dockerhub.leffss.local/kubesphere/ks-installer:v3.1.1
        imagePullPolicy: "Always"
        resources:

開始安裝

kubectl apply -f kubesphere-installer.yaml
kubectl apply -f cluster-configuration.yaml

驗證安裝

安裝完成後,會看到以下內容:

#####################################################
###              Welcome to KubeSphere!           ###
#####################################################

Console: http://192.168.0.2:30880
Account: admin
Password: P@88w0rd

NOTES:
  1. After logging into the console, please check the
     monitoring status of service components in
     the "Cluster Management". If any service is not
     ready, please wait patiently until all components
     are ready.
  2. Please modify the default password after login.

#####################################################
https://kubesphere.io             20xx-xx-xx xx:xx:xx
#####################################################

現在,可以通過 http://{IP}:30880 使用預設帳戶和密碼 admin/P@88w0rd 訪問 KubeSphere 的 Web 控制檯。

啟用可插拔元件

從 2.1.0 版本開始,KubeSphere 解耦了一些核心功能元件。這些元件設計成了可插拔式,這樣可以在安裝之前或之後啟用它們。如果不啟用它們,KubeSphere 會預設以最小化進行安裝部署。

不同的可插拔元件部署在不同的名稱空間中。可以根據需求啟用任意元件。強烈建議安裝這些可插拔元件來深度體驗 KubeSphere 提供的全棧特性和功能。

有關如何啟用每個元件的更多資訊,請參見本章的各個教程。

各元件資源要求

在啟用可插拔元件之前,請確保環境中有足夠的資源,具體參見下表。否則,可能會因為缺乏資源導致元件崩潰。

CPU 和記憶體的資源請求和限制均指單個副本的要求。

KubeSphere 監控系統

名稱空間 kubesphere-monitoring-system kubesphere-monitoring-system kubesphere-monitoring-system
子元件 2 x Prometheus 3 x Alertmanager Notification Manager
CPU 請求 100 m 10 m 100 m
CPU 限制 4 core 500 m
記憶體請求 400 MiB 30 MiB 20 MiB
記憶體限制 8 GiB 1 GiB
安裝 必需 必需 必需
備註 Prometheus 的記憶體消耗取決於叢集大小。8 GiB 可滿足 200 個節點/16,000 個 Pod 的叢集規模。

KubeSphere 監控系統不是可插拔元件,會預設安裝。它與其他元件(例如日誌系統)緊密關聯,因此將其資源請求和限制也列在本頁中,供您參考。

KubeSphere 應用商店

名稱空間 openpitrix-system
CPU 請求 0.3 core
CPU 限制
記憶體請求 300 MiB
記憶體限制
安裝 可選
備註 提供應用商店進行應用生命週期管理。建議安裝。

KubeSphere DevOps 系統

名稱空間 kubesphere-devops-system kubesphere-devops-system
安裝模式 All-in-One 安裝 多節點安裝
CPU 請求 34 m 0.47 core
CPU 限制
記憶體請求 2.69 G 8.6 G
記憶體限制
安裝 可選 可選
備註 提供一站式 DevOps 解決方案,包括 Jenkins 流水線、B2I 和 S2I。 其中一個節點的記憶體必須大於 8 G。

KubeSphere 日誌系統

名稱空間 kubesphere-logging-system kubesphere-logging-system kubesphere-logging-system kubesphere-logging-system
子元件 3 x Elasticsearch fluent bit kube-events kube-auditing
CPU 請求 50 m 20 m 90 m 20 m
CPU 限制 1 core 200 m 900 m 200 m
記憶體請求 2 G 50 MiB 120 MiB 50 MiB
記憶體限制 100 MiB 1200 MiB 100 MiB
安裝 可選 必需 可選 可選
備註 可選元件,用於儲存日誌資料。不建議在生產環境中使用內建 Elasticsearch。 日誌收集代理。啟用日誌系統後,它是必需元件。 Kubernetes 事件收集、過濾、匯出和告警。 Kubernetes 和 KubeSphere 審計日誌收集、過濾和告警。

KubeSphere 告警和通知

名稱空間 kubesphere-alerting-system
CPU 請求 0.08 core
CPU 限制
記憶體請求 80 M
記憶體限制
安裝 可選
備註 告警和通知需要同時啟用。

KubeSphere 服務網格

名稱空間 istio-system
CPU 請求 1 core
CPU 限制
記憶體請求 3.5 G
記憶體限制
安裝 可選
備註 支援灰度釋出策略、流量拓撲、流量管理和分散式鏈路追蹤。

KubeSphere 應用商店

作為一個開源的、以應用為中心的容器平臺,KubeSphere 在 OpenPitrix 的基礎上,為使用者提供了一個基於 Helm 的應用商店,用於應用生命週期管理。OpenPitrix 是一個開源的 Web 平臺,用於打包、部署和管理不同型別的應用。KubeSphere 應用商店讓 ISV、開發者和使用者能夠在一站式服務中只需點選幾下就可以上傳、測試、部署和釋出應用。

對內,KubeSphere 應用商店可以作為不同團隊共享資料、中介軟體和辦公應用的場所。對外,有利於設立構建和交付的行業標準。預設情況下,應用商店中內建了 17 個應用。啟用該功能後,可以通過應用模板新增更多應用。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

openpitrix:
  store:
    enabled: true # 將“false”更改為“true”。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 openpitrix,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
openpitrix:
  store:
    enabled: true # 將“false”更改為“true”。
  1. 您可以使用 Web Kubectl 工具執行以下命令來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

您可以通過點選控制檯右下角的 找到 Web Kubectl 工具。

驗證

在登入控制檯後,如果能看到頁面左上角的應用商店以及其中的 17 個內建應用,則說明安裝成功。

在多叢集架構中使用應用商店

在多叢集架構中,一個 Host 叢集(H 叢集)管理所有 Member 叢集(M 叢集)。與 KubeSphere 中的其他元件不同,應用商店是所有叢集(包括 H 叢集和 M 叢集)的全域性應用程式池。只需要在 H 叢集上啟用應用商店,便可以直接在 M 叢集上使用應用商店的相關功能(無論 M 叢集是否啟用應用商店),例如應用模板和應用倉庫。

但是,如果只在 M 叢集上啟用應用商店而沒有在 H 叢集上啟用,將無法在多叢集架構中的任何叢集上使用應用商店。

KubeSphere DevOps 系統

基於 Jenkins 的 KubeSphere DevOps 系統是專為 Kubernetes 中的 CI/CD 工作流設計的,它提供了一站式的解決方案,幫助開發和運維團隊用非常簡單的方式構建、測試和釋出應用到 Kubernetes。它還具有外掛管理、Binary-to-Image (B2I)、Source-to-Image (S2I)、程式碼依賴快取、程式碼質量分析、流水線日誌等功能。

DevOps 系統為使用者提供了一個自動化的環境,應用可以自動釋出到同一個平臺。它還相容第三方私有映象倉庫(如 Harbor)和程式碼庫(如 GitLab/GitHub/SVN/BitBucket)。它為使用者提供了全面的、視覺化的 CI/CD 流水線,打造了極佳的使用者體驗,而且這種相容性強的流水線能力在離線環境中非常有用。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

devops:
  enabled: true # 將“false”更改為“true”。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 devops,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
devops:
  enabled: true # 將“false”更改為“true”。
  1. 您可以使用 Web Kubectl 工具執行以下命令來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

您可以通過點選控制檯右下角的 找到 Web Kubectl 工具。

驗證

方法一:進入服務元件,檢查 DevOps 的狀態。

方法二:

執行以下命令來檢查 Pod 的狀態:

kubectl get pod -n kubesphere-devops-system

如果元件執行成功,輸出結果如下:

NAME                          READY   STATUS    RESTARTS   AGE
ks-jenkins-5cbbfbb975-hjnll   1/1     Running   0          40m
s2ioperator-0                 1/1     Running   0          41m

KubeSphere 日誌系統

KubeSphere 為日誌收集、查詢和管理提供了一個強大的、全面的、易於使用的日誌系統。它涵蓋了不同層級的日誌,包括租戶、基礎設施資源和應用。使用者可以從專案、工作負載、Pod 和關鍵字等不同維度對日誌進行搜尋。與 Kibana 相比,KubeSphere 基於租戶的日誌系統中,每個租戶只能檢視自己的日誌,從而可以在租戶之間提供更好的隔離性和安全性。除了 KubeSphere 自身的日誌系統,該容器平臺還允許使用者新增第三方日誌收集器,如 Elasticsearch、Kafka 和 Fluentd。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

logging:
  enabled: true # 將“false”更改為“true”。

預設情況下,如果啟用了日誌系統,ks-installer 將安裝內建 Elasticsearch。對於生產環境,如果您想啟用日誌系統,強烈建議在 cluster-configuration.yaml 中設定以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在安裝前提供以下資訊後,ks-installer 將直接對接外部 Elasticsearch,不再安裝內建 Elasticsearch。

es:  # Storage backend for logging, tracing, events and auditing.
  elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
  elasticsearchDataReplicas: 1     # The total number of data nodes.
  elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
  elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
  logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
  elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
  externalElasticsearchUrl: # The URL of external Elasticsearch.
  externalElasticsearchPort: # The port of external Elasticsearch.

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯。點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration。點選結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 logging,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
logging:
  enabled: true # 將“false”更改為“true”。

預設情況下,如果啟用了日誌系統,將會安裝內建 Elasticsearch。對於生產環境,如果您想啟用日誌系統,強烈建議在該 YAML 檔案中設定以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在檔案中提供以下資訊後,KubeSphere 將直接對接外部 Elasticsearch,不再安裝內建 Elasticsearch。

es:  # Storage backend for logging, tracing, events and auditing.
  elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
  elasticsearchDataReplicas: 1     # The total number of data nodes.
  elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
  elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
  logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
  elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
  externalElasticsearchUrl: # The URL of external Elasticsearch.
  externalElasticsearchPort: # The port of external Elasticsearch.
  1. 您可以使用 Web Kubectl 工具執行以下命令來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

方法一:進入服務元件,檢查 Logging 的狀態

方法二:

執行以下命令來檢查 Pod 的狀態:

kubectl get pod -n kubesphere-logging-system

如果元件執行成功,輸出結果如下:

NAME                                          READY   STATUS    RESTARTS   AGE
elasticsearch-logging-data-0                  1/1     Running   0          87m
elasticsearch-logging-data-1                  1/1     Running   0          85m
elasticsearch-logging-discovery-0             1/1     Running   0          87m
fluent-bit-bsw6p                              1/1     Running   0          40m
fluent-bit-smb65                              1/1     Running   0          40m
fluent-bit-zdz8b                              1/1     Running   0          40m
fluentbit-operator-9b69495b-bbx54             1/1     Running   0          40m
logsidecar-injector-deploy-667c6c9579-cs4t6   2/2     Running   0          38m
logsidecar-injector-deploy-667c6c9579-klnmf   2/2     Running   0          38m

KubeSphere 事件系統

KubeSphere 事件系統使使用者能夠跟蹤叢集內部發生的事件,例如節點排程狀態和映象拉取結果。這些事件會被準確記錄下來,並在 Web 控制檯中顯示具體的原因、狀態和資訊。要查詢事件,使用者可以快速啟動 Web 工具箱,在搜尋欄中輸入相關資訊,並有不同的過濾器(如關鍵字和專案)可供選擇。事件也可以歸檔到第三方工具,例如 Elasticsearch、Kafka 或 Fluentd。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

events:
  enabled: true # 將“false”更改為“true”。

對於生產環境,如果您想啟用事件系統,強烈建議在 cluster-configuration.yaml 中設定以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在安裝前提供以下資訊後,ks-installer 將直接對接外部 Elasticsearch,不再安裝內建 Elasticsearch。

es:  # Storage backend for logging, tracing, events and auditing.
  elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
  elasticsearchDataReplicas: 1     # The total number of data nodes.
  elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
  elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
  logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
  elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
  externalElasticsearchUrl: # The URL of external Elasticsearch.
  externalElasticsearchPort: # The port of external Elasticsearch.

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 events,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
events:
  enabled: true # 將“false”更改為“true”。

預設情況下,如果啟用了事件系統,將會安裝內建 Elasticsearch。對於生產環境,如果您想啟用事件系統,強烈建議在該 YAML 檔案中設定以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在檔案中提供以下資訊後,KubeSphere 將直接對接外部 Elasticsearch,不再安裝內建 Elasticsearch。

es:  # Storage backend for logging, tracing, events and auditing.
  elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
  elasticsearchDataReplicas: 1     # The total number of data nodes.
  elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
  elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
  logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
  elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
  externalElasticsearchUrl: # The URL of external Elasticsearch.
  externalElasticsearchPort: # The port of external Elasticsearch.
  1. 可以使用 Web Kubectl 工具執行以下命令來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

方法一:驗證您可以使用右下角工具箱中的事件查詢功能。

方法二:

執行以下命令來檢查 Pod 的狀態:

kubectl get pod -n kubesphere-logging-system

如果元件執行成功,輸出結果如下:

NAME                                          READY   STATUS    RESTARTS   AGE
elasticsearch-logging-data-0                  1/1     Running   0          155m
elasticsearch-logging-data-1                  1/1     Running   0          154m
elasticsearch-logging-discovery-0             1/1     Running   0          155m
fluent-bit-bsw6p                              1/1     Running   0          108m
fluent-bit-smb65                              1/1     Running   0          108m
fluent-bit-zdz8b                              1/1     Running   0          108m
fluentbit-operator-9b69495b-bbx54             1/1     Running   0          109m
ks-events-exporter-5cb959c74b-gx4hw           2/2     Running   0          7m55s
ks-events-operator-7d46fcccc9-4mdzv           1/1     Running   0          8m
ks-events-ruler-8445457946-cl529              2/2     Running   0          7m55s
ks-events-ruler-8445457946-gzlm9              2/2     Running   0          7m55s
logsidecar-injector-deploy-667c6c9579-cs4t6   2/2     Running   0          106m
logsidecar-injector-deploy-667c6c9579-klnmf   2/2     Running   0          106m

KubeSphere 告警系統

告警是可觀測性的重要組成部分,與監控和日誌密切相關。KubeSphere 中的告警系統與其主動式故障通知 (Proactive Failure Notification) 系統相結合,使使用者可以基於告警策略瞭解感興趣的活動。當達到某個指標的預定義閾值時,會向預先配置的收件人發出告警。因此,需要預先配置通知方式,包括郵件、Slack、釘釘、企業微信和 Webhook。有了功能強大的告警和通知系統,就可以迅速發現並提前解決潛在問題,避免業務受影響。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

alerting:
  enabled: true # 將“false”更改為“true”。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 alerting,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
alerting:
  enabled: true # 將“false”更改為“true”。
  1. 可以使用 Web Kubectl 工具執行以下命令來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

如果您在叢集管理頁面可以看到告警訊息和告警策略,說明安裝成功,因為安裝元件之後才會顯示這兩部分。

KubeSphere 審計日誌

KubeSphere 審計日誌系統提供了一套與安全相關並按時間順序排列的記錄,按順序記錄了與單個使用者、管理人員或系統其他元件相關的活動。對 KubeSphere 的每個請求都會生成一個事件,然後寫入 Webhook,並根據一定的規則進行處理。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

auditing:
  enabled: true # 將“false”更改為“true”。

預設情況下,如果啟用了審計功能,ks-installer 會安裝內建 Elasticsearch。對於生產環境,如果您想啟用審計功能,強烈建議在 cluster-configuration.yaml 中設定以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在安裝前提供以下資訊後,ks-installer 將直接對接外部 Elasticsearch,不再安裝內建 Elasticsearch。

es:  # Storage backend for logging, tracing, events and auditing.
  elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
  elasticsearchDataReplicas: 1     # The total number of data nodes.
  elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
  elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
  logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
  elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
  externalElasticsearchUrl: # The URL of external Elasticsearch.
  externalElasticsearchPort: # The port of external Elasticsearch.

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 auditing,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
auditing:
  enabled: true # 將“false”更改為“true”。

預設情況下,如果啟用了審計功能,將安裝內建 Elasticsearch。對於生產環境,如果您想啟用審計功能,強烈建議在該 YAML 檔案中設定以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。提供以下資訊後,KubeSphere 將直接對接外部 Elasticsearch,不再安裝內建 Elasticsearch。

es:  # Storage backend for logging, tracing, events and auditing.
  elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
  elasticsearchDataReplicas: 1     # The total number of data nodes.
  elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
  elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
  logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
  elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
  externalElasticsearchUrl: # The URL of external Elasticsearch.
  externalElasticsearchPort: # The port of external Elasticsearch.
  1. 可以執行以下命令,使用 Web Kubectl 工具來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

方法一:驗證您可以使用右下角工具箱中的操作審計功能。

方法二:

執行以下命令來檢查 Pod 的狀態:

kubectl get pod -n kubesphere-logging-system

如果元件執行成功,輸出結果如下:

NAME                                                              READY   STATUS      RESTARTS   AGE
elasticsearch-logging-curator-elasticsearch-curator-159872n9g9g   0/1     Completed   0          2d10h
elasticsearch-logging-curator-elasticsearch-curator-159880tzb7x   0/1     Completed   0          34h
elasticsearch-logging-curator-elasticsearch-curator-1598898q8w7   0/1     Completed   0          10h
elasticsearch-logging-data-0                                      1/1     Running     1          2d20h
elasticsearch-logging-data-1                                      1/1     Running     1          2d20h
elasticsearch-logging-discovery-0                                 1/1     Running     1          2d20h
fluent-bit-6v5fs                                                  1/1     Running     1          2d20h
fluentbit-operator-5bf7687b88-44mhq                               1/1     Running     1          2d20h
kube-auditing-operator-7574bd6f96-p4jvv                           1/1     Running     1          2d20h
kube-auditing-webhook-deploy-6dfb46bb6c-hkhmx                     1/1     Running     1          2d20h
kube-auditing-webhook-deploy-6dfb46bb6c-jp77q                     1/1     Running     1          2d20h

KubeSphere 服務網格

KubeSphere 服務網格基於 Istio,將微服務治理和流量管理視覺化。它擁有強大的工具包,包括熔斷機制、藍綠部署、金絲雀釋出、流量映象、分散式鏈路追蹤、可觀測性和流量控制等。KubeSphere 服務網格支援程式碼無侵入的微服務治理,幫助開發者快速上手,Istio 的學習曲線也極大降低。KubeSphere 服務網格的所有功能都旨在滿足使用者的業務需求。

KubeSphere v3.1.1 使用的 istio 版本為 v1.6.10

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

servicemesh:
  enabled: true # 將“false”更改為“true”。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 servicemesh,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
servicemesh:
  enabled: true # 將“false”更改為“true”。
  1. 可以執行以下命令,使用 Web Kubectl 工具來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

方法一:進入服務元件,檢視 Istio 的狀態。

方法二:

執行以下命令來檢查 Pod 的狀態:

kubectl get pod -n istio-system

如果元件執行成功,輸出結果可能如下:

NAME                                    READY   STATUS    RESTARTS   AGE
istio-ingressgateway-78dbc5fbfd-f4cwt   1/1     Running   0          9m5s
istiod-1-6-10-7db56f875b-mbj5p          1/1     Running   0          10m
jaeger-collector-76bf54b467-k8blr       1/1     Running   0          6m48s
jaeger-operator-7559f9d455-89hqm        1/1     Running   0          7m
jaeger-query-b478c5655-4lzrn            2/2     Running   0          6m48s
kiali-f9f7d6f9f-gfsfl                   1/1     Running   0          4m1s
kiali-operator-7d5dc9d766-qpkb6         1/1     Running   0          6m53s

網路策略

從 3.0.0 版本開始,使用者可以在 KubeSphere 中配置原生 Kubernetes 的網路策略。網路策略是一種以應用為中心的結構,能夠指定如何允許 Pod 通過網路與各種網路實體進行通訊。通過網路策略,使用者可以在同一叢集內實現網路隔離,這意味著可以在某些例項 (Pod) 之間設定防火牆。

  • 在啟用之前,請確保叢集使用的 CNI 網路外掛支援網路策略。支援網路策略的 CNI 網路外掛有很多,包括 Calico、Cilium、Kube-router、Romana 和 Weave Net 等。
  • 建議您在啟用網路策略之前,使用 Calico 作為 CNI 外掛。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

network:
  networkpolicy:
    enabled: true # 將“false”更改為“true”。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 network.networkpolicy,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
network:
  networkpolicy:
    enabled: true # 將“false”更改為“true”。
  1. 可以執行以下命令,使用 Web Kubectl 工具來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

如果能在網路管理中看到網路策略,說明安裝成功,因為安裝元件之後才會顯示這部分。

Metrics Server

KubeSphere 支援用於部署的 Pod 彈性伸縮程式 (HPA)。在 KubeSphere 中,Metrics Server 控制著 HPA 是否啟用。您可以根據不同型別的指標(例如 CPU 和記憶體使用率,以及最小和最大副本數),使用 HPA 物件對部署 (Deployment) 自動伸縮。通過這種方式,HPA 可以幫助確保您的應用程式在不同情況下都能平穩、一致地執行。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

metrics_server:
  enabled: true # 將“false”更改為“true”。

如果在某些雲託管的 Kubernetes 引擎上安裝 KubeSphere,那麼很可能環境中已經安裝了 Metrics Server。在這種情況下,不建議在 cluster-configuration.yaml 中啟用 Metrics Server,因為這可能會在安裝過程中引起衝突。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該 YAML 檔案中,搜尋到 metrics_server,將 enabled 的 false 改為 true。完成後,點選右下角的更新,儲存配置。
metrics_server:
  enabled: true # 將“false”更改為“true”。
  1. 可以執行以下命令,使用 Web Kubectl 工具來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

執行以下命令以驗證 Metrics Server 的 Pod 在正常執行。

kubectl get pod -n kube-system

如果 Metrics Server 安裝成功,那麼叢集可能會返回以下輸出(不包括無關 Pod):

NAME                                        READY   STATUS    RESTARTS   AGE
metrics-server-6c767c9f94-hfsb7             1/1     Running   0          9m38s

服務拓撲圖

可以啟用服務拓撲圖以整合 Weave Scope(Docker 和 Kubernetes 的視覺化和監控工具)。Weave Scope 使用既定的 API 收集資訊,為應用和容器構建拓撲圖。服務拓撲圖顯示在您的專案中,將服務之間的連線關係視覺化。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

network:
  topology:
    type: weave-scope # 將“none”更改為“weave-scope”。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該配置檔案中,搜尋到 network,將 network.topology.type 更改為 weave-scope。完成後,點選右下角的更新儲存配置。
network:
  topology:
    type: weave-scope # 將“none”更改為“weave-scope”。
  1. 可以執行以下命令,使用 Web Kubectl 工具來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

方法一:進入一個專案中,導航到應用負載下的服務,即可看到拓撲圖選項卡下服務的拓撲圖。

方法二:

執行以下命令來檢查 Pod 的狀態:

kubectl get pod -n weave

如果元件執行成功,輸出結果可能如下:

NAME                                        READY   STATUS    RESTARTS   AGE
weave-scope-agent-48cjp                     1/1     Running   0          3m1s
weave-scope-agent-9jb4g                     1/1     Running   0          3m1s
weave-scope-agent-ql5cf                     1/1     Running   0          3m1s
weave-scope-app-5b76897b6f-8bsls            1/1     Running   0          3m1s
weave-scope-cluster-agent-8d9b8c464-5zlpp   1/1     Running   0          3m1s

容器組 IP 池

容器組 IP 池用於規劃 Pod 網路地址空間,每個容器組 IP 池之間的地址空間不能重疊。建立工作負載時,可選擇特定的容器組 IP 池,這樣創建出的 Pod 將從該容器組 IP 池中分配 IP。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

network:
  ippool:
    type: calico # 將“none”更改為“calico”。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該配置檔案中,搜尋到 network,將 network.ippool.type 更改為 calico。完成後,點選右下角的更新儲存配置。
network:
  ippool:
    type: calico # 將“none”更改為“calico”。
  1. 可以執行以下命令,使用 Web Kubectl 工具來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

在叢集管理頁面,可以在網路管理下看到容器組 IP 池。

KubeEdge

KubeEdge 是一個開源系統,用於將容器化應用程式編排功能擴充套件到邊緣的主機。KubeEdge 支援多個邊緣協議,旨在對部署於雲端和邊端的應用程式與資源等進行統一管理。

KubeEdge 的元件在兩個單獨的位置執行——雲上和邊緣節點上。在雲上執行的元件統稱為 CloudCore,包括 Controller 和 Cloud Hub。Cloud Hub 作為接收邊緣節點發送請求的閘道器,Controller 則作為編排器。在邊緣節點上執行的元件統稱為 EdgeCore,包括 EdgeHub,EdgeMesh,MetadataManager 和 DeviceTwin。有關更多資訊,請參見 KubeEdge 網站。

啟用 KubeEdge 後,可以為叢集新增邊緣節點並在這些節點上部署工作負載。

安裝 KubeSphere 前

修改 cluster-configuration.yaml 檔案中開啟

kubeedge:
  enabled: true # 將“false”更改為“true”。

將 kubeedge.cloudCore.cloudHub.advertiseAddress 的值設定為叢集的公共 IP 地址或邊緣節點可以訪問的 IP 地址。

安裝 KubeSphere 後

  1. 以 admin 身份登入控制檯,點選左上角的平臺管理,選擇叢集管理。
  2. 點選自定義資源 CRD,在搜尋欄中輸入 clusterconfiguration,點選搜尋結果檢視其詳細頁面。
  3. 在資源列表中,點選 ks-installer 右側的 ,選擇編輯配置檔案。
  4. 在該配置檔案中,搜尋到 kubeedge.enabled,將 false 更改為 true 以啟用 KubeEdge。
kubeedge:
  enabled: true # 將“false”更改為“true”。
  1. 將 kubeedge.cloudCore.cloudHub.advertiseAddress 的值設定為叢集的公共 IP 地址或邊緣節點可以訪問的 IP 地址。完成後,點選右下角的更新儲存配置。

如果叢集是從 KubeSphere v3.0.0 升級而來,cluster-configuration.yaml 中不會包含 KubeEdge 的配置。有關更多資訊,請參見如何在升級後啟用 KubeEdge

  1. 可以執行以下命令,使用 Web Kubectl 工具來檢查安裝過程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

驗證

方法一:在叢集管理頁面,您可以看到節點管理下出現邊緣節點板塊。

方法二:

執行以下命令來檢查 Pod 的狀態:

kubectl get pod -n kubeedge

如果元件執行成功,輸出結果可能如下:

NAME                                              READY   STATUS    RESTARTS   AGE
cloudcore-5f994c9dfd-r4gpq                        1/1     Running   0          5h13m
edge-watcher-controller-manager-bdfb8bdb5-xqfbk   2/2     Running   0          5h13m
iptables-hphgf                                    1/1     Running   0          5h13m

如果您在啟用 KubeEdge 時未設定 kubeedge.cloudCore.cloudHub.advertiseAddress,則 CloudCore 無法正常執行 (CrashLoopBackOff)。在這種情況下,請執行 kubectl -n kubeedge edit cm cloudcore 新增叢集的公共 IP 地址或邊緣節點可以訪問的 IP 地址。