在本教程中,您将创建一个 Google Kubernetes Engine (GKE) Enterprise 版本集群,并使用 Config Sync 同步到多代码库示例代码库中的配置。
假设您的合规团队负责确保组织中的所有人都遵循内部规则。为了强制执行这些规则,合规团队创建了配置,这些配置已添加到示例代码库中。组织中的每个集群都必须同步到该代码库,并且您需要负责创建和同步集群。
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Make sure that you have the following role or roles on the project: GKE Hub Admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
进入 IAM - 选择项目。
- 点击 授予访问权限。
-
在新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。
- 在选择角色列表中,选择一个角色。
- 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
- 点击 Save(保存)。
-
创建集群
在本部分中,您将创建一个集群,供本教程使用。在实际场景中,您可能会管理多个集群,但为了简化本教程,您只需创建和管理一个集群。
如需创建集群,请完成以下步骤:
启用 Google Kubernetes Engine (GKE) Enterprise 版本 API。这对于 Config Sync 至关重要。
在 Google Cloud 控制台中,转到 Kubernetes Engine 页面。
点击 add_box 创建。
在 Autopilot 部分中,选择配置。
在集群基本信息部分的名称字段中输入
cs-cluster
。在集群层级部分中,选择企业层级。将其他所有字段保留为建议的默认值。
点击创建。您将转到 Kubernetes 集群页面。创建集群可能需要几分钟时间。 如果您在集群旁边的状态列中看到绿色对勾标记,则表示该集群已准备就绪。
配置集群
现在您已创建了一个集群,接下来可以配置 Config Sync 以同步到示例代码库的 config-sync-quickstart
目录中的配置。
如需在 Google Cloud 控制台中配置 Config Sync,请完成以下步骤:
- 在 Google Cloud 控制台中,转到功能部分下的配置页面。
- 点击 add 安装 Config Sync。
- 选择自动升级,使 Config Sync 可以自动升级版本。
- 在安装选项下,选择 Install Config Sync on individual clusters(在个别集群上安装 Config Sync)。
- 在可用集群表中,选择
cs-cluster
,然后点击 Install Config Sync(安装 Config Sync)。在设置标签页中,您应该会在几分钟后看到cs-cluster
的状态为已启用。 - 在 Config Sync 信息中心上,点击部署集群软件包。
- 在选择要部署软件包的集群表中,选择
cs-cluster
,然后点击继续。 - 保留托管在 Git 上的软件包,然后点击继续。
- 在软件包名称字段中,输入
sample-repository
。 - 在代码库网址字段中,输入
https://github.com/GoogleCloudPlatform/anthos-config-management-samples
。 - 在路径字段中,输入
config-sync-quickstart/multirepo/root
。 - 其他所有字段保留默认值。
点击部署软件包。
几分钟后,您应该会在
cs-cluster
的同步状态列中看到已同步。
现在 Config Sync 已同步到代码库,因此它会持续协调集群的状态与代码库中的配置。
查看软件包详细信息
如需查看由 Config Sync 管理的所有对象,请在软件包标签页中点击 cs-cluster
,然后查看软件包详细信息页面。在此页面中,您可以简要了解每个软件包同步的所有资源,以及资源类型和资源同步到的命名空间等详细信息。
您可以转到 GitHub 中代码库的 /config-sync-quickstart/multirepo/ 文件夹,探索引发系统创建这些命名空间的配置。 config-sync-quickstart
目录包含 ClusterRole、CustomResourceDefinition、Rolebinding、Namespace 和 RepoSync 配置。它还包含用于监控的 Prometheus Operator 配置。
清理
转到 Google Cloud 控制台中的 GKE 菜单。
在
cs-cluster
旁边,点击 more_vert 操作,然后点击 delete 删除。当系统提示您确认时,再次点击删除。
后续步骤
- 了解如何验证配置。