apiVersion:core.cnrm.cloud.google.com/v1beta1kind:ConfigConnectormetadata:# the name is restricted to ensure that there is only ConfigConnector resource installed in your clustername:configconnector.core.cnrm.cloud.google.comspec:mode:namespacedstateIntoSpec:Absent
使用 kubectl apply 将配置应用到集群:
kubectlapply-fconfigconnector.yaml
配置 Config Connector 以管理命名空间中的资源
在以下部分中,您安装 Config Connector 的 Google Cloud 项目称为“宿主项目”或 HOST_PROJECT_ID。您管理资源的其他项目称为“代管式项目”或 MANAGED_PROJECT_ID。如果您仅打算使用 Config Connector 在与您的集群相同的项目中创建 Google Cloud 资源,则这些项目可能是同一项目。
创建命名空间
如果您已有用于组织Google Cloud 资源的命名空间,则可以跳过此步骤。
通过运行以下命令,使用 kubectl 创建新的命名空间:
kubectlcreatenamespaceNAMESPACE
将 NAMESPACE 替换为命名空间的名称。
创建身份
创建 Identity and Access Management (IAM) 服务账号,并在 IAM 服务账号和 Config Connector Kubernetes 服务账号之间创建绑定:
创建 IAM 服务账号。 如果您原本有一个服务账号,则可以使用原有的账号,而不必新建服务账号。通过运行以下命令,使用 gcloud 创建服务账号:
apiVersion:core.cnrm.cloud.google.com/v1beta1kind:ConfigConnectorContextmetadata:# you can only have one ConfigConnectorContext per namespacename:configconnectorcontext.core.cnrm.cloud.google.comnamespace:NAMESPACEspec:googleServiceAccount:"NAMESPACE_GSA@HOST_PROJECT_ID.iam.gserviceaccount.com"stateIntoSpec:Absent
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThis document details how to install and configure Config Connector in namespaced mode, which enables management of multiple Google Cloud projects with distinct identities.\u003c/p\u003e\n"],["\u003cp\u003eTo set up namespaced mode, users must first install Config Connector and then apply a specific YAML configuration (\u003ccode\u003econfigconnector.yaml\u003c/code\u003e) to the cluster via \u003ccode\u003ekubectl\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor each namespace intended to manage resources, an IAM service account needs to be created, granted elevated permissions in the managed project, and bound to Config Connector's Kubernetes service account.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eConfigConnectorContext\u003c/code\u003e object must be created in each namespace to enable Config Connector to watch and manage resources within it, and this object can be removed to stop managing the namespace.\u003c/p\u003e\n"],["\u003cp\u003eUninstalling Config Connector involves deleting Config Connector resources, CRDs, controller components, and the Config Connector operator, but these steps should not be used for Config Controller clusters.\u003c/p\u003e\n"]]],[],null,["# Install Config Connector in namespaced mode\n===========================================\n\n*** ** * ** ***\n\nThis page explains how to install Config Connector in namespaced mode.\n\nInstalling in namespaced mode is an extension of the Config Connector\ninstallation. Namespaced mode supports managing multiple projects,\neach with their own Google Cloud identities.\n\nBefore you begin\n----------------\n\nBefore configuring Config Connector to run in namespaced mode, ensure that you\nhave [installed Config Connector](/config-connector/docs/concepts/installation-types).\n\n### Configure Config Connector to run in namespaced mode\n\nTo enable namespaced mode, complete the following steps:\n\n1. Copy the following YAML manifest into a file named\n `configconnector.yaml`:\n\n apiVersion: core.cnrm.cloud.google.com/v1beta1\n kind: ConfigConnector\n metadata:\n # the name is restricted to ensure that there is only ConfigConnector resource installed in your cluster\n name: configconnector.core.cnrm.cloud.google.com\n spec:\n mode: namespaced\n stateIntoSpec: Absent\n\n2. Apply the configuration to your cluster with `kubectl apply`:\n\n kubectl apply -f configconnector.yaml\n\nConfigure Config Connector to manage resources in your namespaces\n-----------------------------------------------------------------\n\n| **Note:** You must perform these steps for every namespace that you want Config Connector to create resources from.\n\nIn the following sections, the Google Cloud project where you install\nConfig Connector is known as the *host project* , or \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e.\nThe other projects where you manage resources are known as the *managed projects* , or\n\u003cvar translate=\"no\"\u003eMANAGED_PROJECT_ID\u003c/var\u003e. These could be the same project if you only intend to\nuse Config Connector to create Google Cloud resources in the same project as\nyour cluster.\n\n### Creating a namespace\n\nYou can skip this step if you already have a namespace to use to organize\nGoogle Cloud resources.\n\nUse `kubectl` to create a new namespace by running the following command: \n\n kubectl create namespace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with a name for the namespace.\n\n### Creating an identity\n\nCreate an Identity and Access Management (IAM) service account and create a binding between the\nIAM Service Account and the Config Connector Kubernetes service\naccount:\n\n1. Create an IAM service account. If you have an existing\n service account, you can use it instead of creating a new service account. Use\n `gcloud` to create the service account by running the following command:\n\n gcloud iam service-accounts create \u003cvar translate=\"no\"\u003eNAMESPACE_GSA\u003c/var\u003e --project \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNAMESPACE_GSA\u003c/var\u003e with the name of the Google service account (GSA) bound to your namespace.\n - \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e with your host project's ID.\n\n To learn more about creating service accounts, see\n [Creating and managing service accounts](/iam/docs/creating-managing-service-accounts).\n2. Give the IAM service account elevated permissions on\n your *managed* project.\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003eMANAGED_PROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003eNAMESPACE_GSA\u003c/var\u003e@\u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com\" \\\n --role=\"roles/owner\"\n\n Replace \u003cvar translate=\"no\"\u003eMANAGED_PROJECT_ID\u003c/var\u003e with your managed project's ID.\n | **Note:** If you prefer to grant [editor](/iam/docs/understanding-roles#basic-definitions) access to the project replace `roles/owner` with `roles/editor`. Granting the editor role allows most Config Connector functionality except Project or Organization wide configurations such as IAM modifications.\n3. Create an IAM policy binding between the\n IAM service account and the Config Connector Kubernetes\n service account. You bind the service accounts by running the following\n `gcloud` command:\n\n gcloud iam service-accounts add-iam-policy-binding \\\n \u003cvar translate=\"no\"\u003eNAMESPACE_GSA\u003c/var\u003e@\u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e.svc.id.goog[cnrm-system/cnrm-controller-manager-\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e]\" \\\n --role=\"roles/iam.workloadIdentityUser\"\n\n Replace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with your namespace.\n4. Give the IAM service account permissions to publish\n Prometheus metrics to Google Cloud Observability on your *host* project.\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003eNAMESPACE_GSA\u003c/var\u003e@\u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com\" \\\n --role=\"roles/monitoring.metricWriter\"\n\n### Creating a ConfigConnectorContext\n\nTo create Google Cloud resources, you need to configure Config Connector\nto watch your namespace by adding a `ConfigConnectorContext` object\nin the namespace you want to use.\n\nTo create a `ConfigConnectorContext`, complete the following steps:\n\n1. Copy the following YAML manifest into a file named\n `configconnectorcontext.yaml`:\n\n apiVersion: core.cnrm.cloud.google.com/v1beta1\n kind: ConfigConnectorContext\n metadata:\n # you can only have one ConfigConnectorContext per namespace\n name: configconnectorcontext.core.cnrm.cloud.google.com\n namespace: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eNAMESPACE\u003c/span\u003e\u003c/var\u003e\n spec:\n googleServiceAccount: \"\u003cvar translate=\"no\"\u003eNAMESPACE_GSA\u003c/var\u003e@\u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com\"\n stateIntoSpec: Absent\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with the name of your namespace.\n - \u003cvar translate=\"no\"\u003eNAMESPACE_GSA\u003c/var\u003e with the name of the Google service account bound to your namespace.\n - \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e with your host project's ID.\n2. Apply the file to your cluster with `kubectl`:\n\n kubectl apply -f configconnectorcontext.yaml\n\n3. Verify that the Config Connector Operator created a Kubernetes service\n account for your namespace with `kubectl` by running the following command:\n\n kubectl get serviceaccount/cnrm-controller-manager-\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e -n cnrm-system\n\n Replace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with the name of your namespace.\n4. Verify that the Config Connector controller Pod is running for your namespace\n with `kubectl` by running the following command:\n\n kubectl wait -n cnrm-system \\\n --for=condition=Ready pod \\\n -l cnrm.cloud.google.com/component=cnrm-controller-manager \\\n -l cnrm.cloud.google.com/scoped-namespace=\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with the name of your namespace.\n\n If the Config Connector controller is running, the output is similar to: \n\n cnrm-controller-manager-abcdefghijk-0 condition met.\n\nConfigure Config Connector to no longer manage resources in your namespace\n--------------------------------------------------------------------------\n\nTo configure Config Connector to no longer manage your namespace, you remove all\nConfig Connector resources in your namespace and delete the `ConfigConnectorContext`\nin your namespace.\n\n### Remove the Config Connector resources in your namespace\n\nTo finalize the removal of `ConfigConnectorContext`, remove all Config Connector\nresources from your namespace.\n\n1. To discover all Config Connector resources in your namespace, for each Config Connector\n Custom Resource Definition, list all resources.\n\n kubectl get gcp -n \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with the name of your namespace.\n2. To remove all Config Connector resources, for each resource in the output of\n the previous step, issue a delete command.\n\n kubectl delete -n \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e \u003cvar translate=\"no\"\u003eKIND\u003c/var\u003e \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e: the name of your namespace\n - \u003cvar translate=\"no\"\u003eKIND\u003c/var\u003e: the kind of the resource discovered in the previous step\n - \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e: the name of the resource discovered in the previous step\n\n### Remove the ConfigConnectorContext\n\nTo configure Config Connector to no longer manage the Config Connector resources\nin your namespace, delete `ConfigConnectorContext` in your namespace. \n\n kubectl delete -n \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e ConfigConnectorContext configconnectorcontext.core.cnrm.cloud.google.com\n\nReplace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with the name of your namespace.\n\nThe deletion of `ConfigConnectorContext` will not finalize until all Config Connector\nresources are removed from your namespace.\n\nUninstalling Config Connector\n-----------------------------\n\nDon't use the following the steps to uninstall a\n[Config Controller](/anthos-config-management/docs/concepts/config-controller-overview)\ncluster.\n\nUse `kubectl delete` to remove the Config Connector CRDs along with\ncontroller components: \n\n kubectl delete ConfigConnectorContext --all -A --wait=false\n\n kubectl delete ConfigConnector configconnector.core.cnrm.cloud.google.com \\\n --wait=true\n\nTo uninstall the Config Connector operator, run the following command: \n\n kubectl delete -f operator-system/configconnector-operator.yaml --wait=true\n\nWhat's next\n-----------\n\n- [Get started](/config-connector/docs/how-to/getting-started) with Config Connector.\n- [Learn about best practices](/config-connector/docs/best-practices) for Config Connector."]]