本頁說明如何為現有車隊產生叢集清單。機群的叢集清單可讓您使用開放原始碼和第三方整合功能,這些功能會使用 ClusterProfile 規格。
叢集清單是機群的開放原始碼對應項目,能有條理地將 Kubernetes 叢集和其他資源分組,並一同管理。ClusterProfile 規格包含的資訊是車隊資訊的子集。
ClusterProfile 同步功能會在車隊和叢集清單之間進行單向同步。啟用 ClusterProfile 同步處理後,車隊就是事實來源,車隊的任何變更都會由 ClusterProfile 同步處理自動套用至叢集清單。直接對叢集設定檔資源所做的變更,不會套用至車隊。
事前準備
啟用 ClusterProfile 同步
系統會針對機群中的一個叢集執行 ClusterProfile 同步作業。這個叢集稱為中心叢集,可用於執行需要機群中其餘叢集資訊的多叢集控制器。多叢集控制器範例包括 Argo CD 控制器和多叢集協調器。建議您不要在中心叢集中執行其他工作負載。
如要在叢集上啟用 ClusterProfile 同步功能,請新增 fleet-clusterinventory-management-cluster=true
標籤。您可以執行以下操作:
- 建立新叢集做為中心叢集。如要在新叢集上啟用 ClusterProfile 同步功能,請參閱下一節。
- 在機群中找出要當做中心叢集的叢集。請參閱下一節,瞭解如何在現有叢集上啟用 ClusterProfile 同步功能。
為機群啟用 ClusterProfile 同步功能後,系統會使用 ClusterProfile API,自動為機群中的每個叢集建立叢集設定檔。當車隊有異動時,系統會自動建立、更新及刪除這些叢集設定檔。
在新叢集上啟用 ClusterProfile 同步
如要為中心叢集建立叢集,並啟用 ClusterProfile 同步,請使用下列指令:
gcloud container clusters create CLUSTER --location LOCATION --enable-fleet
--labels=fleet-clusterinventory-management-cluster=true
更改下列內容:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
根據預設,叢集設定檔會在 fleet-cluster-inventory
命名空間中建立。如要變更命名空間,請指定
fleet-clusterinventory-namespace
標籤。
gcloud container clusters update CLUSTER --location LOCATION
--update-labels=fleet-clusterinventory-namespace=NAMESPACE
更改下列內容:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
- NAMESPACE:產生叢集設定檔的命名空間。如未指定,叢集設定檔會在
fleet-cluster-inventory
命名空間中產生。
在現有叢集上啟用 ClusterProfile 同步
如要在現有叢集上啟用 ClusterProfile 同步功能,請使用下列指令:
gcloud container clusters update CLUSTER --location LOCATION
--update-labels=fleet-clusterinventory-management-cluster=true
更改下列內容:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
根據預設,叢集設定檔會在 fleet-cluster-inventory
命名空間中建立。如要變更命名空間,請指定
fleet-clusterinventory-namespace
標籤。
gcloud container clusters update CLUSTER --location LOCATION
--update-labels=fleet-clusterinventory-namespace=NAMESPACE
更改下列內容:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
- NAMESPACE:產生叢集設定檔的命名空間。如未指定,叢集設定檔會在
fleet-cluster-inventory
命名空間中產生。
確認已啟用 ClusterProfile 同步
確認中樞叢集包含 fleet-clusterinventory-management-cluster = true
標籤,驗證 ClusterProfile 同步處理是否已啟用。如要執行此操作,請使用下列指令:
gcloud container clusters describe CLUSTER --location LOCATION
取代下列項目:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
畫面會顯示如下的輸出內容:
resourceLabels:
fleet-clusterinventory-management-cluster: 'true'
驗證產生的叢集設定檔資源
使用下列指令,確認中樞叢集是否已產生叢集設定檔資源:
gcloud container clusters get-credentials CLUSTER --location LOCATION
kubectl get clusterprofiles -n fleet-cluster-inventory
更改下列內容:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
畫面上應該會顯示類似以下的輸出內容:
NAME AGE
cluster-1-us-west1 10s
cluster-2-us-west1 20s
這項輸出內容應包含機群中每個叢集的叢集設定檔。
叢集設定檔名稱的格式為 MEMBERSHIP-
LOCATION。
查看叢集設定檔內容
如要查看特定叢集的叢集設定檔內容,請使用下列指令:
kubectl get clusterprofile CLUSTER-LOCATION -n fleet-cluster-inventory -o yaml
更改下列內容:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
畫面上應該會顯示類似以下的輸出內容:
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ClusterProfile
metadata:
annotations:
fleet.gke.io/membershipName: projects/123456789/locations/us-west1/memberships/cluster-1
labels:
x-k8s.io/cluster-manager: gke-fleet
name: cluster-1-us-west1
namespace: fleet-cluster-inventory
停用 ClusterProfile 同步
在機群的 Hub 叢集上移除 fleet-clusterinventory-management-cluster
標籤,即可停用 ClusterProfile 同步:
gcloud container clusters update CLUSTER --location LOCATION \
--remove-labels=fleet-clusterinventory-management-cluster
更改下列內容:
- CLUSTER:
google_container_cluster
資源的名稱。 - LOCATION:叢集的建立位置。
後續步驟
- 如要進一步瞭解如何將 ClusterProfile 同步處理作業與 Argo CD 整合,請參閱「Argo CD ClusterProfile Syncer」。
- 多叢集 Orchestrator 會使用叢集設定檔。有助於排定多叢集和多區域部署作業。詳情請參閱多叢集協調器總覽。