本页介绍了如何为现有车队生成集群目录。借助舰队的集群目录,您可以使用使用 ClusterProfile 规范的开源和第三方集成。
集群目录是舰队的开源等效项:即 Kubernetes 集群及其他可共同管理的资源的逻辑分组。ClusterProfile 规范包含的信息是车队中信息的一部分。
ClusterProfile 同步功能是指车队和集群目录之间的单向同步。启用 ClusterProfile 同步后,车队将成为可靠来源,并且对车队所做的任何更改都会通过 ClusterProfile 同步自动应用于集群目录。直接对集群配置文件资源所做的更改不会应用于车队。
准备工作
确保您已按照一般前提条件使用车队。
创建车队或指定要使用的现有车队。
向运行此页面上命令的用户授予所需的 Identity and Access Management 角色 (
roles/gkehub.editor
)。您需要拥有此角色才能更新车队成员资格。
识别集群中心
ClusterProfile 同步会针对舰队中的一个集群运行。此集群称为枢纽集群,可用于运行需要舰队中其他集群信息的多集群控制器。多集群控制器示例包括 Argo CD 控制器和多集群编排器。
确定要用作枢纽集群的舰队中的集群。
启用 ClusterProfile 同步
为舰队启用 ClusterProfile 同步功能后,该功能会使用 ClusterProfile API 自动为舰队中的每个集群创建集群配置文件。当您更改舰队时,系统会自动创建、更新和删除这些集群配置文件。
使用 fleet-clusterinventory-management-cluster = true
标记中心集群的舰队成员资格,以启用 ClusterProfile 同步。为此,请使用以下命令:
gcloud container fleet memberships update MEMBERSHIP --location LOCATION
--update-labels=fleet-clusterinventory-management-cluster=true
替换以下内容:
- MEMBERSHIP:集群成员资格名称。
- LOCATION:注册 Hub 集群的位置。
默认情况下,集群配置文件会在 fleet-cluster-inventory
命名空间中创建。如需更改命名空间,请指定 fleet-clusterinventory-namespace
标签。
gcloud container fleet memberships update MEMBERSHIP --location LOCATION
--update-labels=fleet-clusterinventory-namespace=NAMESPACE
替换以下内容:
- MEMBERSHIP:集群成员资格名称。
- LOCATION:生成集群配置文件的位置。
- NAMESPACE:生成集群配置文件的命名空间。如果未指定,集群配置文件将在
fleet-cluster-inventory
命名空间中生成。
验证是否已启用 ClusterProfile 同步
通过验证集群中心成员资格是否包含 fleet-clusterinventory-management-cluster = true
标签,验证是否已启用 ClusterProfile 同步。为此,请使用以下命令:
gcloud container fleet memberships describe MEMBERSHIP --location LOCATION
替换以下内容:
- MEMBERSHIP:集群成员资格名称。
- LOCATION:集群的注册位置。
输出应类似如下所示:
labels:
fleet-clusterinventory-management-cluster: 'true'
验证生成的集群配置文件资源
使用以下命令验证集群配置文件资源是否已在枢纽集群中生成:
gcloud container fleet memberships get-credentials MEMBERSHIP --location LOCATION
kubectl get clusterprofiles -n fleet-cluster-inventory
替换以下内容:
- MEMBERSHIP:集群成员资格名称。
- LOCATION:集群的注册位置。
输出应类似于以下内容:
NAME AGE
cluster-1-us-west1 10s
cluster-2-us-west1 20s
此输出应包含舰队中每个集群的集群配置文件。集群配置文件名称的格式为 MEMBERSHIP-
LOCATION。
查看集群配置文件的内容
如需查看特定集群的集群配置文件的内容,请使用以下命令:
kubectl get clusterprofile MEMBERSHIP-LOCATION -n fleet-cluster-inventory -o yaml
替换以下内容:
- MEMBERSHIP:集群成员资格名称。
- 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 同步
移除 fleet-clusterinventory-management-cluster
舰队成员资格标签,以在舰队的中心集群上停用 ClusterProfile 同步:
gcloud container fleet memberships update MEMBERSHIP --location LOCATION \
--remove-labels=fleet-clusterinventory-management-cluster
替换以下内容:
- MEMBERSHIP:集群成员资格名称。
- LOCATION:集群的注册位置。
后续步骤
- 如需详细了解如何将 ClusterProfile 同步与 Argo CD 集成,请参阅 Argo CD ClusterProfile Syncer。
- 多集群编排器使用集群配置文件。它有助于安排多集群和多区域部署。如需了解详情,请参阅多集群编排器概览。