在以下示例中,如果 Cloud Service Mesh 收到健康检查结果,表明在 us-central1 中运行购物车微服务的虚拟机 (VM) 实例不健康,Cloud Service Mesh 会指示前端微服务的边车代理将流量故障转移到在 asia-southeast1 中运行的购物车微服务。由于自动扩缩功能与 Google Cloud中的流量管理集成,Cloud Service Mesh 会将额外流量通知 asia-southeast1 中的 MIG,且 MIG 会扩大规模。
Cloud Service Mesh 检测到“支付”微服务的所有后端都处于健康状态,因此 Cloud Service Mesh 会指示“购物车”微服务的 Envoy 代理将一部分流量(最多为客户配置的容量)发送到 asia-southeast1,其余流量则溢出到 us-central1。
在全球负载均衡部署中使用 Cloud Service Mesh 进行故障切换(点击可放大)
Cloud Service Mesh 中的负载均衡组件
在设置 Cloud Service Mesh 期间,您可以配置多个负载均衡组件:
包含配置值的后端服务。
运行健康检查,为部署中的虚拟机和 Google Kubernetes Engine (GKE) pod 的提供健康检查。
对于服务路由 API,Mesh 或 Gateway 资源和 Route 资源。
对于负载均衡 API,一种全局转发规则,其中包括 VIP 地址、目标代理和网址映射。
与 xDS API 兼容的边车代理(例如 Envoy)在客户端虚拟机实例或 Kubernetes pod 中运行。Cloud Service Mesh 用作控制平面,并使用 xDS API 直接与每个代理进行通信。在数据平面中,应用将流量发送到转发规则或 Mesh 资源中配置的 VIP 地址。边车代理或 gRPC 应用会拦截流量并将其重定向到相应的后端。
下图显示了在 Compute Engine 虚拟机或 GKE Pod 上运行的应用、组件以及 Cloud Service Mesh 部署中的流量流向。其中显示了 Cloud Service Mesh 和用于确定流量路由的 Cloud Load Balancing 资源。下图显示了旧版负载均衡 API。
[[["易于理解","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,["# Cloud Service Mesh load balancing\n=================================\n\nCloud Service Mesh uses sidecar proxies or proxyless gRPC to deliver global load\nbalancing for your internal microservices. You can deploy internal microservices\n(sidecar proxy-based or proxyless gRPC-based) with instances in multiple\nregions. Cloud Service Mesh provides health, routing, and backend information to\nthe sidecar proxies or proxyless gRPC, enabling them to perform optimal traffic\nrouting to application instances in multiple cloud regions for a service.\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\nIn the following diagram, user traffic enters a Google Cloud\ndeployment through an external global load balancer. The external load balancer\ndistributes traffic to the Front End microservice in either\n`us-central1` or `asia-southeast1`, depending on the location of the end user.\n\nThe internal deployment features three global microservices: Front End, Shopping\nCart, and Payments. Each service runs on managed instance groups (MIGs) in two\nregions, `us-central1` and `asia-southeast1`. Cloud Service Mesh uses a global\nload-balancing algorithm that directs traffic from the user in California to the\nmicroservices deployed in `us-central1`. Requests from the user in\nSingapore are directed to the microservices in `asia-southeast1`.\n\nAn incoming user request is routed to the Front End microservice. The service\nproxy installed on the host with the Front End then directs traffic to the\nShopping Cart. The sidecar proxy installed on the host with the Shopping Cart\ndirects traffic to the Payments microservice. In a proxyless gRPC environment,\nyour gRPC application would handle traffic management.\n[](/static/service-mesh/v1.23/docs/images/td-global-lb.svg) Cloud Service Mesh in a global load-balancing deployment (click to enlarge)\n\nIn the following example, if Cloud Service Mesh receives health check results\nthat indicate that the virtual machine (VM) instances running the Shopping Cart\nmicroservice in `us-central1` are unhealthy, Cloud Service Mesh instructs the\nsidecar proxy for the Front End microservices to fail over traffic to the Shopping\nCart microservice running in `asia-southeast1`. Because autoscaling is\nintegrated with traffic management in Google Cloud, Cloud Service Mesh\nnotifies the MIG in `asia-southeast1` of the additional traffic, and the MIG\nincreases in size.\n\nCloud Service Mesh detects that all backends of the Payments microservice are\nhealthy, so Cloud Service Mesh instructs Envoy's proxy for the Shopping Cart to\nsend a portion of the traffic---up to the customer's configured\ncapacity---to `asia-southeast1` and overflow the rest to `us-central1`.\n[](/static/service-mesh/v1.23/docs/images/td-global-lb-failover.svg) Failover with Cloud Service Mesh in a global load-balancing deployment (click to enlarge)\n\nLoad-balancing components in Cloud Service Mesh\n-----------------------------------------------\n\nDuring Cloud Service Mesh setup, you configure several load-balancing\ncomponents:\n\n- The backend service, which contains configuration values.\n- A health check, which provides health checking for the VMs and Google Kubernetes Engine (GKE) Pods in your deployment.\n- With the service routing APIs, a `Mesh` or `Gateway` resource and a `Route` resource.\n- With the load balancing APIs, a global forwarding rule, which includes the VIP address, a target proxy, and a URL map.\n\nAn xDS API-compatible sidecar proxy (such as Envoy) runs on a client\nVM instance or in a Kubernetes Pod. Cloud Service Mesh serves as the control\nplane and uses xDS APIs to communicate directly with each proxy. In the data\nplane, the application sends traffic to the VIP address configured in the\nforwarding rule or `Mesh` resource. The sidecar proxy or your gRPC application\nintercepts the traffic and redirects it to the appropriate backend.\n\nThe following diagram shows an application running on Compute Engine VMs or\nGKE Pods, the components, and the traffic flow in a\nCloud Service Mesh deployment. It shows Cloud Service Mesh and the\nCloud Load Balancing resources that are used to determine traffic routing.\nThe diagram shows the older load balancing APIs.\n[](/static/service-mesh/v1.23/docs/images/td-resources.svg) Cloud Service Mesh resources to be configured (click to enlarge)\n\nWhat's next\n-----------\n\n- To learn about configuring advance load balancing features, see [Advanced load balancing overview](/service-mesh/v1.23/docs/service-routing/advanced-load-balancing-overview).\n- To learn more about service discovery and traffic interception, see [Cloud Service Mesh service discovery](/service-mesh/v1.23/docs/traffic-management/service-discovery).\n- To learn more about Cloud Service Mesh with the service routing APIs, see the [overview](/service-mesh/v1.23/docs/service-routing/overview)."]]