手动安装 Config Connector
本页介绍了如何手动安装 Config Connector。
如需详细了解不同的安装选项,请参阅选择安装类型。
手动安装方法可以提供比使用插件更快的更新速度。
在以下说明中,Config Connector 配置为集群模式,这意味着将有一个全局 Config Connector 控制器被冒充为单个 Google Cloud IAM 服务账号。随着您在同一集群中添加更多 Config Connector 资源并引入更多 Kubernetes 命名空间,您可能需要考虑改用命名空间模式,这种模式具有更高的可伸缩性,并为多租户用例(例如管理多个项目中的资源)提供了更好的 IAM 权限隔离。 Google Cloud
准备工作
在手动安装 Config Connector Operator 之前,请完成以下步骤:
- 创建或指定尚未安装 Config Connector 且启用了 Workload Identity 和 Kubernetes Engine Monitoring 的 GKE 集群。
- 配置
kubectl
以关联到您的集群。
安装 Config Connector Operator
Config Connector 使用 Kubernetes Operator 使其安装保持最新。如需安装此 Operator,请完成以下步骤:
下载最新的 Config Connector tar 文件:
gcloud storage cp gs://configconnector-operator/latest/release-bundle.tar.gz release-bundle.tar.gz
解压缩 tar 文件:
tar zxvf release-bundle.tar.gz
在集群上安装 Config Connector Operator:
对于 GKE Autopilot 集群:
kubectl apply -f operator-system/autopilot-configconnector-operator.yaml
对于 GKE Standard 集群:
kubectl apply -f operator-system/configconnector-operator.yaml
创建身份
Config Connector 通过使用 Identity and Access Management (IAM) 服务账号进行身份验证以及使用 GKE 的 Workload Identity 将 IAM 服务账号与 Kubernetes 服务账号绑定来创建和管理资源。 Google Cloud
如需创建身份,请完成以下步骤:
-
创建 IAM 服务账号。 如果您希望使用现有服务账号,则可以使用该账号并跳过此步骤。
如需创建服务账号,请使用以下命令: 将gcloud iam service-accounts create SERVICE_ACCOUNT_NAME
SERVICE_ACCOUNT_NAME
替换为您的服务账号的名称。 - 向 IAM 服务账号授予对项目的提升权限:
替换以下内容:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/editor"
PROJECT_ID
替换为您的项目 ID。- 将
SERVICE_ACCOUNT_NAME
替换为您的服务账号的名称。
- 在 IAM 服务账号与 Config Connector 运行的预定义 Kubernetes 服务账号之间创建 IAM 政策绑定:
替换以下内容:gcloud iam service-accounts add-iam-policy-binding \ SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \ --member="serviceAccount:PROJECT_ID.svc.id.goog[cnrm-system/cnrm-controller-manager]" \ --role="roles/iam.workloadIdentityUser"
- 将
SERVICE_ACCOUNT_NAME
替换为您的服务账号的名称。 PROJECT_ID
替换为您的项目 ID。
- 将
如需详细了解如何创建服务账号,请参阅创建和管理服务账号。
配置 Config Connector
要完成安装,请为 ConfigConnector
CustomResource 创建配置文件,然后使用 kubectl apply
命令应用该配置文件。Config Connector Operator 在集群中安装Google Cloud resource CRD 和 Config Connector 组件。
如需将 Operator 配置为集群模式,请完成以下步骤:
- 将以下 YAML 文件复制到名为
configconnector.yaml
的文件中: 替换以下内容:# configconnector.yaml apiVersion: core.cnrm.cloud.google.com/v1beta1 kind: ConfigConnector metadata: # the name is restricted to ensure that there is only one # ConfigConnector resource installed in your cluster name: configconnector.core.cnrm.cloud.google.com spec: mode: cluster googleServiceAccount: "SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" # Setting `stateIntoSpec` to `Absent` is recommended. It means setting `cnrm.cloud.google.com/state-into-spec` # annotation to `absent` for all Config Connector resources created in the cluster in the future. # It prevents Config Connector from populating unspecified fields into the spec. stateIntoSpec: Absent
- 将
SERVICE_ACCOUNT_NAME
替换为您的服务账号的名称。 PROJECT_ID
替换为您的项目 ID。
- 将
- 使用
kubectl apply
将配置应用到集群:kubectl apply -f configconnector.yaml
指定创建资源的位置
Config Connector 可以按项目、文件夹或组织整理资源,这与使用 Google Cloud整理资源的方式相同。
在使用 Config Connector 创建资源之前,必须先配置创建资源的位置。为了确定创建资源的位置,Config Connector 会在资源配置或现有命名空间中使用注释。如需了解详情,请参阅整理资源。
如果您没有可用于此目的的命名空间,请使用kubectl
创建一个命名空间。kubectl create namespace NAMESPACE
将 NAMESPACE
替换为您的命名空间名称。 例如 config-connector
。
选择一个标签页以便选择 Config Connector 创建资源的位置。
项目
如需在特定项目中创建资源,请运行以下命令:
kubectl annotate namespace \ NAMESPACE cnrm.cloud.google.com/project-id=PROJECT_ID
请替换以下内容:
- 将
NAMESPACE
替换为您的命名空间名称。 - 将
PROJECT_ID
替换为您的 Google Cloud 项目 ID。
文件夹
如需在特定文件夹中创建资源,请运行以下命令:
kubectl annotate namespace \ NAMESPACE cnrm.cloud.google.com/folder-id=FOLDER_ID
请替换以下内容:
- 将
NAMESPACE
替换为您的命名空间名称。 - 将
FOLDER_ID
替换为您的 Google Cloud 文件夹 ID。
组织
如需在特定组织中创建资源,请运行以下命令:
kubectl annotate namespace \ NAMESPACE cnrm.cloud.google.com/organization-id=ORGANIZATION_ID
请替换以下内容:
- 将
NAMESPACE
替换为您的命名空间名称。 - 将
ORGANIZATION_ID
替换为您的 Google Cloud 组织 ID。
为命名空间添加注释时,Config Connector 将在相应的项目、文件夹或组织中创建资源。如需详细了解 Config Connector 如何使用 Kubernetes 命名空间,请参阅 Kubernetes 命名空间和 Google Cloud 项目。
验证安装
Config Connector 在命名空间 cnrm-system
中运行其所有组件。您可以通过运行以下命令来验证 Pod 是否准备就绪:
kubectl wait -n cnrm-system \
--for=condition=Ready pod --all
如果正确安装了 Config Connector,则输出类似于以下内容:
pod/cnrm-controller-manager-0 condition met
升级 Config Connector
下载并安装最新版本的 Config Connector Operator:
gcloud storage cp gs://configconnector-operator/latest/release-bundle.tar.gz release-bundle.tar.gz
tar zxvf release-bundle.tar.gz
kubectl apply -f operator-system/configconnector-operator.yaml
降级 Config Connector
不支持完全降级 Config Connector。如需同时降级 Config Connector Operator 和 CRD,您必须卸载并重新安装 Config Connector,然后重新应用资源。
在 Config Connector 1.123.1 版及更高版本中,您可以回滚使用命名空间模式的安装的 Operator 版本。在包含要回滚的 Operator 的每个命名空间中,将 ConfigConnectorContext
对象中的 spec.version
字段设置为之前的 Config Connector 版本。
您最多可以将 Config Connector 控制器回滚 3 个次小版本。您始终必须回滚到给定次要版本的最新补丁版本。
卸载 Config Connector
使用 kubectl delete
移除 Config Connector CRD 和控制器组件:
kubectl delete ConfigConnector configconnector.core.cnrm.cloud.google.com \
--wait=true
如需卸载 Config Connector Operator,请运行以下命令:
kubectl delete -f operator-system/configconnector-operator.yaml --wait=true
从非 Operator 安装升级
Config Connector 1.33.0 版及更高版本仅支持使用 GKE 插件或 Operator 进行安装。
如需升级到 Operator(并保留所有 Config Connector 资源),您必须移除除 CRD 之外的所有 Config Connector 系统组件,然后安装 Operator。
运行以下命令以移除 Config Connector 系统非 CRD 组件:
kubectl delete sts,deploy,po,svc,roles,clusterroles,clusterrolebindings --all-namespaces -l cnrm.cloud.google.com/system=true --wait=true kubectl delete validatingwebhookconfiguration abandon-on-uninstall.cnrm.cloud.google.com --ignore-not-found --wait=true kubectl delete validatingwebhookconfiguration validating-webhook.cnrm.cloud.google.com --ignore-not-found --wait=true kubectl delete mutatingwebhookconfiguration mutating-webhook.cnrm.cloud.google.com --ignore-not-found --wait=true
从插件切换为手动安装
作为插件安装时,Config Connector 的版本与已安装的 GKE 版本直接相关。
手动安装可以加快更新速度,但需要进行手动升级。
如需在保证安全的同时保留所有资源,请执行以下操作:
停用插件,而不删除任何
ConfigConnector
或ConfigConnectorContext
对象:gcloud container clusters update CLUSTER_NAME --update-addons ConfigConnector=DISABLED
将
CLUSTER_NAME
替换为您在其中安装 Config Connector 的集群的名称。按照说明安装所需版本的手动 Operator。
后续步骤
- Config Connector 使用入门。
- 了解 Config Connector 的最佳实践。