[[["易于理解","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。"],[],[],null,["Migrating from In-cluster to Managed Canonical Service Controller\n\n\n**Note:** Canonical Services are supported automatically in Cloud Service Mesh version 1.6.8 and higher.\n\nThis guide describes the steps to migrate from in-cluster Canonical Service\nController to the Managed Canonical Service Controller.\n\nThe in-cluster Canonical Service Controller has been deprecated and will no\nlonger receive updates. While existing deployments of in-cluster controller will\ncontinue to operate, we strongly recommend migrating to the managed Canonical\nService Controller to ensure compatibility with future releases, access to the\nlatest features, and continued support. All the Cloud Service Mesh\ninstallations with asmcli from version 1.25 will be provisioned with the managed\nCanonical Service controller.\n\n1. Enable the Cloud Service Mesh fleet feature\n\nThe Managed Canonical Service controller is installed as part of the\nCloud Service Mesh fleet feature, which is enabled using the following\ncommand:\n\n\u003cbr /\u003e\n\n```\n gcloud container fleet mesh enable --project FLEET_PROJECT_ID\n \n```\n\n\u003cbr /\u003e\n\nReplace `FLEET_PROJECT_ID` with the ID of your Fleet Host project. Generally,\nthe FLEET_PROJECT_ID has the same name as the project.\n\nNote that if you plan to register multiple clusters, enabling\nCloud Service Mesh happens at the fleet-level so you only have to run this\ncommand once.\n\nGrant permissions to the Cloud Service Mesh service accounts\n\nIf your cluster's project differs from your fleet host project, you must allow\nCloud Service Mesh service accounts in the fleet project to access the\ncluster project.\n\nYou only need to do this once for each cluster project. If you previously\nconfigured managed Cloud Service Mesh for this combination of cluster and\nfleet projects, then these changes have already been applied and you don't\nhave to run the following commands.\n\nGrant service accounts in the fleet project permission to access the cluster\nproject: \n\n gcloud projects add-iam-policy-binding \"\u003cvar translate=\"no\"\u003eCLUSTER_PROJECT_ID\u003c/var\u003e\" \\\n --member \"serviceAccount:service-\u003cvar translate=\"no\"\u003eFLEET_PROJECT_NUMBER\u003c/var\u003e@gcp-sa-servicemesh.iam.gserviceaccount.com\" \\\n --role roles/anthosservicemesh.serviceAgent\n\nReplace \u003cvar translate=\"no\"\u003eCLUSTER_PROJECT_ID\u003c/var\u003e with the project ID for your\ncluster and the \u003cvar translate=\"no\"\u003eFLEET_PROJECT_NUMBER\u003c/var\u003e with the project number\nfor your fleet.\n\nTo determine the project number for your fleet, see the instructions on the\n[Google Cloud projects](https://developers.google.com/apps-script/guides/cloud-platform-projects#determine_the_id_number_of_a_standard)\ndocument.\n\n2. Disable the in-cluster Canonical Service Controller\n\nThe Managed Canonical Service Controller cannot function alongside the\nIn-cluster Canonical Service controller. Therefore, you must disable the\nin-cluster controller.\n\n1. **Check for In-Cluster Controller**: Verify if the in-cluster canonical\n controller is present.\n\n kubectl get deployment canonical-service-controller-manager -n asm-system\n\n2. **Delete the In-Cluster Controller**: If the deployment is found, then you\n can delete it (and the entirety of the asm-system namespace) by running the\n following command:\n\n kubectl delete namespace asm-system\n\n3. Verify the Managed Canonical Controller is operational\n\nThe Managed Canonical Service Controller reports its status in the feature\nstate, so you can confirm the installation is working correctly by checking the\nfeature state:\n\n1. **Check Feature State:** Retrieve the feature state using the following\n command:\n\n ```\n gcloud container fleet mesh describe --project FLEET_PROJECT_ID\n ```\n2. **Verify Status:** Check the state of your cluster and verify that the\n `state.code` is `OK`.\n\n - **Important:** It may take up to 15 minutes for the state to transition to `OK`. Wait and re-run the command.\n - **Proceed to the next step only when the `state.code` is `OK`.**\n - If the `state.code` does not become `OK` after 15 minutes, refer to [Resolve Managed Canonical Service Controller issues](/service-mesh/docs/troubleshooting/troubleshoot-canonical-service#resolve-managed-canonical-controller-issues) for troubleshooting guidance.\n\n Example output: \n\n membershipStates:\n projects/\u003cproject-number\u003e/locations/\u003clocation\u003e/memberships/\u003cmembership-name\u003e:\n state:\n code: OK\n description:\n Revision(s) ready for use: istiod-asm-183-2.\n\n3. **Check Managed Canonical Controller is functional:** Verify that the\n managed canonical controller is functioning correctly by deploying a pod\n with sidecar injected and check if the controller automatically creates the\n corresponding canonical service.\n\n 1. Create a namespace with automatic sidecar injection enabled:\n\n ```\n kubectl create namespace NAMESPACE_NAME\n ```\n\n Follow the section [Enabling automatic sidecar injection](/service-mesh/docs/onboarding/kubernetes-workloads#enabling_automatic_sidecar_injection) to enable\n automatic sidecar injection in the newly created namespace.\n 2. Create a YAML file named `simple_pod.yaml` with the following content:\n\n apiVersion: v1\n kind: Pod\n metadata:\n name: simple-pod\n labels:\n app: my-app\n spec:\n containers:\n - name: my-container\n image: nginx:latest\n ports:\n - containerPort: 80\n\n The `app` label determines the name of the canonical service. For more\n information, see [Defining Canonical Service](/service-mesh/docs/define-canonical-service).\n 3. Deploy the pod with the following command. Replace NAMESPACE_NAME with the\n name of the namespace where you enabled automatic sidecar injection.\n\n ```\n kubectl apply -f simple_pod.yaml -n NAMESPACE_NAME\n ```\n 4. Confirm pod has been created:\n\n ```\n kubectl get pods -n NAMESPACE_NAME\n ```\n\n Example output: \n\n NAME READY STATUS RESTARTS AGE\n simple-pod 2/2 Running 0 9s\n\n `Note`: Confirm that the READY column shows `2/2`. This indicates that\n both the main container and the sidecar proxy are running correctly. If\n you see a different value, it's likely that automatic sidecar injection\n is not enabled for the namespace.\n 5. Verify Canonical Service Creation: Run the following command to list all\n Canonical Services in the namespace. Verify that the Canonical Service\n `my-app` is created.\n\n ```\n kubectl get canonicalservices -n NAMESPACE_NAME\n ```\n\n Example output: \n\n NAME AGE\n my-app 3s\n\n 6. Cleanup: Delete the pod, canonical service and the namespace:\n\n ```\n kubectl delete -f simple_pod.yaml -n NAMESPACE_NAME\n kubectl delete canonicalservices my-app -n NAMESPACE_NAME\n kubectl delete namespace NAMESPACE_NAME\n ```\n\n **Troubleshooting:**\n - If the required canonical service is not created, refer to [Resolving Canonical Service issues in Cloud Service Mesh](/service-mesh/docs/troubleshooting/troubleshoot-canonical-service).\n - If the issue persists, you can revert to the in-cluster controller. Refer [Revert to the In-Cluster Canonical Service Controller](#revert-back).\n\nRevert back to the In-Cluster Canonical Service Controller\n\nIf you encounter issues with the Managed Canonical Service Controller, you can\nreinstall the in-cluster controller with the following command: \n\n kubectl apply -f \\\n https://raw.githubusercontent.com/GoogleCloudPlatform/anthos-service-mesh-packages/release-1.25/asm/canonical-service/controller.yaml\n\nWhat's next\n\nLearn about:\n\n- [Canonical Services](/service-mesh/docs/canonical-service)\n- [Best practices in Canonical Services](/service-mesh/docs/canonical-service-best-practices)\n- [Define a Canonical Service](/service-mesh/docs/define-canonical-service)\n- [Resolving Canonical Service issues](/service-mesh/docs/troubleshooting/troubleshoot-canonical-service)"]]