Cloud Service Mesh 提供服務和端點探索功能,這些功能可讓您將執行程式碼的虛擬機器 (VM) 執行個體和容器執行個體,分組為服務的端點。
Cloud Service Mesh 會監控這些服務,以便與用戶端分享最新的健康檢查資訊。因此,當應用程式使用 Cloud Service Mesh 用戶端 (例如 Envoy Sidecar Proxy 或無 Proxy 的 gRPC 應用程式) 傳送要求時,可獲得服務的最新資訊。
在 Cloud Service Mesh 的脈絡中,「用戶端」是指在 VM 或容器上執行的應用程式碼,會制定要傳送至伺服器的要求。伺服器是接收這類要求的應用程式程式碼。Cloud Service Mesh 用戶端是 Envoy、gRPC 或其他 xDS 用戶端,連線至 Cloud Service Mesh,且屬於資料層。
Cloud Service Mesh 提供服務探索功能,設定 Cloud Service Mesh 時,您會建立後端服務。您也可以定義轉送規則,指定如何將輸出要求 (由應用程式程式碼傳送並由 Cloud Service Mesh 用戶端處理的要求) 比對至特定服務。Cloud Service Mesh 用戶端處理符合規則的要求時,可以選擇應接收要求的服務。
例如:
您有一個執行應用程式的 VM。這個 VM 具有 Envoy 補充 Proxy,可連線至 Cloud Service Mesh,並代表應用程式處理輸出要求。
[[["容易理解","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-03 (世界標準時間)。"],[],[],null,["# Service discovery\n=================\n\nCloud Service Mesh provides service and endpoint discovery. These features\nlet you group the virtual machine (VM) instances and container instances that\nrun your code as *endpoints* of your services.\n| **Note:** This guide only supports Cloud Service Mesh with Google Cloud APIs and does not support Istio APIs. For more information see, [Cloud Service Mesh overview](/service-mesh/docs/overview).\n\nCloud Service Mesh monitors these services so that it can share\nup-to-date [health check](/load-balancing/docs/health-check-concepts) information\nwith its clients. Therefore, when one of your applications uses its\nCloud Service Mesh client (such as an Envoy sidecar proxy or a\nproxyless gRPC application) to send a request, it benefits from up-to-date\ninformation about your services.\n\nIn the context of Cloud Service Mesh, a *client* is application code\nthat runs on a VM or container that formulates requests to send to a server. A\n*server* is application code that receives such requests.\nA *Cloud Service Mesh client* is an Envoy or gRPC or other xDS client\nthat is connected to Cloud Service Mesh and is part of the data plane.\n\nIn the data plane, Envoy or gRPC does the following:\n\n1. It examines a request and matches the request to a *backend service*, a resource that you configure during deployment.\n2. After the request is matched, Envoy or gRPC applies any previously configured traffic or security policies, chooses a backend or endpoint, and directs the request to that backend or endpoint.\n\nService discovery\n-----------------\n\nCloud Service Mesh provides service discovery. When you configure\nCloud Service Mesh, you create backend services. You also define routing rules\nthat specify how an *outbound request* (a request sent by your application code\nand handled by a Cloud Service Mesh client) is matched to a particular service.\nWhen a Cloud Service Mesh client handles a request that matches a rule, it can\nchoose the service that should receive the request.\n\nFor example:\n\n- You have a VM running your application. This VM has an Envoy sidecar proxy that is connected to Cloud Service Mesh and handles outbound requests on behalf of the application.\n- You configured a backend service named `payments`. This backend service has two network endpoint group (NEG) backends that point to various container instances that run the code for your `payments` service.\n- You configured a `Mesh` resource defining a mesh called `sidecar-mesh`.\n- You configured a `Route` resource that defines traffic destinations for the backend service `payments` and the hostname `helloworld-gce`.\n\nWith this configuration, when your application (on the VM) sends an HTTP request\nto `payments.example.com`, the Cloud Service Mesh client knows that\nthis request is destined for the `payments` service.\n\nWhen you use Cloud Service Mesh with proxyless gRPC services, service discovery\nworks similarly. However, a gRPC library acting as a Cloud Service Mesh client\nonly gets information about the services for which you specify an xDS resolver.\nBy default, Envoy gets information about all services configured on the\nVirtual Private Cloud (VPC) network specified in the Envoy bootstrap file.\n\nEndpoint discovery\n------------------\n\nService discovery enables clients to know about your services. Endpoint\ndiscovery enables clients to know about the instances that are running your\ncode.\n\nWhen you create a service, you also specify the backends for that\nservice. These backends are either VMs in managed instance groups (MIGs) or\ncontainers in NEGs. Cloud Service Mesh monitors these MIGs and NEGs so that it\nknows when instances and endpoints are created and removed.\n\nCloud Service Mesh continuously shares up-to-date information about these\nservices with its clients. This information enables clients to avoid sending\ntraffic to endpoints that no longer exist. It also enables clients to learn\nabout new endpoints and take advantage of the additional capacity\nthat these endpoints provide.\n\nBeyond adding endpoints into MIGs or NEGs and setting up Cloud Service Mesh,\nyou don't need any additional configuration to enable service discovery with\nCloud Service Mesh.\n\nSidecar proxy traffic interception in Cloud Service Mesh\n--------------------------------------------------------\n\nCloud Service Mesh supports the sidecar proxy model. Under this model, when an\napplication sends traffic to its destination, the traffic is intercepted and\nredirected it to a port on the sidecar proxy on the host where the application\nis running. The sidecar proxy decides how to load balance the traffic, and then\nsends the traffic to its destination.\n\nWith Cloud Service Mesh and the service routing APIs, traffic interception is\nmanaged automatically.\n\nWhat's next\n-----------\n\n- To learn how Cloud Service Mesh delivers global load balancing for your internal microservices with sidecar proxies, see [Cloud Service Mesh load balancing](/service-mesh/docs/service-routing/load-balancing).\n- To learn more about Cloud Service Mesh, see the [Cloud Service Mesh overview](/service-mesh/docs/overview)."]]