[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["Route traffic from Cloud Run Services to Cloud Service Mesh workloads on GKE\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n| **Note:** This guide only supports Cloud Service Mesh with Istio APIs and does not support Google Cloud APIs. For more information see, [Cloud Service Mesh overview](/service-mesh/docs/overview).\n\nThis page shows you how to securely route network traffic from\nCloud Run Services to Cloud Service Mesh workloads on\nGKE to use Istio APIs and make use of a fully-managed Envoy\nsidecar.\n\nBefore you begin\n\nThe following sections assume that you have a\n[GKE cluster with Cloud Service Mesh enabled](/service-mesh/docs/onboarding/provision-control-plane).\n\nIf you don't have a GKE Service deployed, use the following\ncommand to deploy a sample service: \n\n cat \u003c\u003cEOF \u003e /tmp/service.yaml\n apiVersion: v1\n kind: Service\n metadata:\n name: ads\n spec:\n ports:\n - port: 9999\n targetPort: 8000\n selector:\n run: ads\n type: ClusterIP\n ---\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: ads\n spec:\n replicas: 1\n selector:\n matchLabels:\n run: ads\n template:\n metadata:\n labels:\n run: ads\n spec:\n containers:\n - image: docker.io/waip/simple-http:v1.0.1\n name: my-http2-svc\n ports:\n - protocol: TCP\n containerPort: 8000\n securityContext:\n fsGroup: 1337\n EOF\n kubectl apply -f /tmp/service.yaml\n\nConfigure a Custom Domain for `VirtualService` hosts\n\nA [virtual service](https://istio.io/latest/docs/reference/config/networking/virtual-service/)\ndefines traffic routing rules. Any matched traffic is then sent to a named\ndestination service\n\n1. Create a new managed zone:\n\n gcloud dns managed-zones create \u003cvar translate=\"no\"\u003eZONE_NAME\u003c/var\u003e \\\n --description=\"zone for service mesh routes\" \\\n --dns-name=\u003cvar translate=\"no\"\u003eDNS_SUFFIX\u003c/var\u003e. \\\n --networks=\u003cvar translate=\"no\"\u003edefault\u003c/var\u003e \\\n --visibility=private\n\n where:\n - \u003cvar translate=\"no\"\u003eZONE_NAME\u003c/var\u003e is a name for your zone (example: 'prod').\n - \u003cvar translate=\"no\"\u003eDNS_SUFFIX\u003c/var\u003e is any valid DNS host (example: 'mesh.private').\n2. Create a resource record set:\n\n IP=10.0.0.1\n gcloud dns record-sets create '*.'\"\u003cvar translate=\"no\"\u003eDNS_SUFFIX\u003c/var\u003e.\" --type=A --zone=\"\u003cvar translate=\"no\"\u003eZONE_NAME\u003c/var\u003e\" \\\n --rrdatas=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-m\"\u003e10\u003c/span\u003e.0.0.1\u003c/var\u003e --ttl 3600\n\n Ensure the IP (RFC 1918 required) is unused. Alternatively,\n [reserve a static internal IP](/vpc/docs/reserve-static-internal-ip-address#reservenewip).\n3. Export a `VirtualService` for External Cloud Run Clients:\n\n cat \u003c\u003cEOF \u003e virtual-service.yaml\n apiVersion: networking.istio.io/v1alpha3\n kind: VirtualService\n metadata:\n name: \u003cvar translate=\"no\"\u003eVIRTUAL_SERVICE_NAME\u003c/var\u003e\n namespace: \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e\n spec:\n hosts:\n - \u003cvar translate=\"no\"\u003eGKE_SERVICE_NAME\u003c/var\u003e.\u003cvar translate=\"no\"\u003eDNS_SUFFIX\u003c/var\u003e\n gateways:\n - external-mesh\n http:\n - route:\n - destination:\n host: \u003cvar translate=\"no\"\u003eGKE_SERVICE_NAME\u003c/var\u003e\n EOF\n kubectl apply -f virtual-service.yaml\n\n where:\n - \u003cvar translate=\"no\"\u003eVIRTUAL_SERVICE_NAME\u003c/var\u003e is a name for your `VirtualService`.\n - \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e is `default` if you're using the provided example service; otherwise, replace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with your namespace name.\n - \u003cvar translate=\"no\"\u003eGKE_SERVICE_NAME\u003c/var\u003e is `ads` if you're using the provided example service; otherwise, replace \u003cvar translate=\"no\"\u003eGKE_SERVICE_NAME\u003c/var\u003e with a name for your GKE service.\n\nWhile it is feasible to add an `external-mesh` gateway as a target to a\npre-existing `VirtualService`, you should establish a distinct `VirtualService`\nto export a Kubernetes service to external Cloud Run clients. Having a\nseparate `VirtualService` facilitates the management of exported services and\ntheir configurations without affecting existing GKE clients.\nAdditionally, some fields in `VirtualServices` are disregarded for mesh external\n`VirtualServices` but continue to function as anticipated for GKE\nservices. So managing and troubleshooting `VirtualServices` separately may be\nadvantageous.\n\nFor GKE clients to also receive the `VirtualService` configuration,\nthe `mesh` or `mesh/default` gateway must be added.\n\nThe mesh external `VirtualService` must be defined in the same namespace as the\nKubernetes Service in the `VirtualService` destination.\n\nConfigure a Cloud Run Service to join a service mesh\n\nTo join a Cloud Run Service to a service mesh, perform the following steps:\n\n1. Determine the mesh ID backing the Cloud Service Mesh GKE\n cluster:\n\n MESH=$(kubectl get controlplanerevision --namespace istio-system -o json | jq -r '.items[0].metadata.annotations[\"mesh.cloud.google.com/external-mesh\"]')\n\n2. Deploy a Cloud Run Service using the mesh ID, making sure to also connect to\n the cluster's VPC network:\n\n gcloud alpha run deploy --mesh \"$MESH\" --network \u003cvar translate=\"no\"\u003edefault\u003c/var\u003e \\\n mesh-svc --image=fortio/fortio \\\n --region=\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e --no-allow-unauthenticated\n\n3. Verify that the Cloud Run service is able to send a request to the\n GKE workload:\n\n TEST_SERVICE_URL=$(gcloud run services describe mesh-svc --region \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e --format=\"value(status.url)\" --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e)\n\n curl -H \"Authorization: Bearer $(gcloud auth print-identity-token)\" \"$TEST_SERVICE_URL/fortio/fetch/\u003cvar translate=\"no\"\u003eGKE_SERVICE_NAME\u003c/var\u003e.\u003cvar translate=\"no\"\u003eDNS_SUFFIX\u003c/var\u003e\"\n\n The output should be a valid HTTP 200 response.\n\nTroubleshooting\n\nThis section shows you how to troubleshoot common errors with\nCloud Service Mesh and Cloud Run.\n\nCloud Run Sidecar Logs\n\nEnvoy errors are logged in Cloud Logging.\n\nFor example an error such as the following will be logged if the\nCloud Run service account is not given the trafficdirector client role\nin the mesh project: \n\n StreamAggregatedResources gRPC config stream to trafficdirector.googleapis.com:443 closed: 7, Permission 'trafficdirector.networks.getConfigs' denied on resource '//trafficdirector.googleapis.com/projects/525300120045/networks/mesh:test-mesh/nodes/003fb3e0c8927482de85f052444d5e1cd4b3956e82b00f255fbea1e114e1c0208dbd6a19cc41694d2a271d1ab04b63ce7439492672de4499a92bb979853935b03d0ad0' (or it may not exist).\n\nCSDS\n\nThe trafficdirector client state can be retrieved using CSDS: \n\n gcloud alpha container fleet mesh debug proxy-status --membership=\u003cCLUSTER_MEMBERSHIP\u003e --location=\u003cCLUSTER_LOCATION\u003e\n External Clients:\n ....\n\nWhat's next\n\n- [Route traffic from Cloud Service Mesh workloads to Cloud Run Services](/service-mesh/docs/route-to-cloud-run)"]]