手动安装 Config Connector
本页介绍了如何手动安装 Config Connector。
如需详细了解不同的安装选项,请参阅选择安装类型。
手动安装方法可以提供比使用插件更快的更新速度。
在以下说明中,Config Connector 配置为集群模式,这意味着将有一个全局 Config Connector 控制器被冒充为单个 Google Cloud IAM 服务账号。随着您在同一集群中添加更多 Config Connector 资源并引入更多 Kubernetes 命名空间,您可能需要考虑改用命名空间模式,这种模式具有更高的可伸缩性,并为多租户用例(例如管理多个 Google Cloud 项目中的资源)提供了更好的 IAM 权限隔离。
准备工作
在手动安装 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
配置 IAM 政策以连接到 Google Cloud API
如需让 Config Connector 使用适用于 GKE 的工作负载身份联合管理您的资源,请创建 IAM 政策。 Google Cloud
如需配置政策绑定,请创建一个 IAM 许可政策,引用在您在集群上安装 Config Connector 时自动创建的 Kubernetes ServiceAccount:
gcloud projects add-iam-policy-binding projects/PROJECT_ID \
--role=roles/iam.workloadIdentityUser \
--member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/cnrm-system/cnrm-controller-manager \
--condition=None
替换以下内容:
PROJECT_ID
:您的 Google Cloud 项目 ID。PROJECT_NUMBER
:您的数字 Google Cloud项目编号。NAMESPACE
:Config Connector ServiceAccount 的 Kubernetes 命名空间的名称。如果您未显式创建命名空间,则值为default
。
配置 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 # 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
- 使用
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 版本。
您最多可以回滚 3 个次要版本的 Config Connector 控制器。您始终必须回滚到给定次要版本的最新补丁版本。
卸载 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 的最佳实践。