本文档仅适用于使用负载均衡 API 的 Cloud Service Mesh。我们强烈建议您使用服务路由 API 来部署 Cloud Service Mesh。
Cloud Service Mesh 使用转发规则来确定将网格中的流量路由到的目标代理。
每条转发规则都会为某项服务提供一个全局 IPv4 地址。您可以使用该地址为您的服务创建内部 DNS 记录(例如,使用 Cloud DNS 托管专用区域)。转发规则中的元数据过滤器会指定与 xDS 兼容的 Sidecar 代理接收配置的条件。
对于 Cloud Service Mesh 控制平面,内部,自行管理和全局转发规则通过 IP 地址、端口和协议将流量路由到目标代理。该代理指向包含确定流量目的地的规则的网址映射。网址映射还会指定默认后端服务。此后端服务指定健康检查并确定适当的后端,例如包含虚拟机 (VM) 实例的托管实例组 (MIG) 或包含 Google Kubernetes Engine (GKE) 后端 Pod 的网络端点组 (NEG)。
下图展示了转发规则如何适应 Cloud Service Mesh 架构。
突出显示的 Cloud Service Mesh 转发规则(点击可放大)
转发规则属性
转发规则资源包含以下适用于 Cloud Service Mesh 的属性。转发规则会处理与目标 IP 地址、协议和端口号匹配的流量。
转发规则中的 0.0.0.0 IP 地址是使用 Cloud Service Mesh 时的选项之一。0.0.0.0 IP 地址表示任何 IP 地址。
使用代理部署时,如果找不到其他特定匹配,则 0.0.0.0 IP 地址允许代理匹配任何传入流量。
在无代理部署中,0.0.0.0 IP 地址提供了一种指定不需要 IP 地址的方法。详细了解如何将 0.0.0.0 IP 地址与目标 gRPC 代理搭配使用。
Cloud Service Mesh 转发规则的 IP 地址不需要与 Virtual Private Cloud (VPC) 网络中子网的 IP 地址范围相对应。对于给定的 VPC 网络、IP 地址和端口,您只能有一个内部自行管理的转发规则。
例如,在同一 VPC 网络中,无法创建两个使用 0.0.0.0 IP 地址和端口 80 的转发规则。
具有目标 gRPC 代理的 IPAddress
引用目标 gRPC 代理并将 validateForProxyless字段设置为 TRUE 的转发规则必须将其 IP 地址设置为 0.0.0.0。
使用 xds 架构的 gRPC 客户端不会执行 DNS 查找来解析通道 URI 中的主机名。相反,此类客户端会通过向 Cloud Service Mesh 发送监听器发现服务 (LDS) 请求来解析目标 URI 中的 hostname[:port]。您不需要执行 DNS 查找,也不需要主机名的 DNS 条目。
因此,Cloud Service Mesh 使用 URI 中指定的 0.0.0.0 IP 地址和端口(默认 80)来查找转发规则。接着,Cloud Service Mesh 会在转发规则引用的目标代理的网址映射中查找匹配的主机规则。
target
✔
此转发规则将流量定向到的目标代理。Cloud Service Mesh 支持 target-http-proxy、target-https-proxy 和 target-grpc-proxy。
当您使用 Google Cloud 控制台配置转发规则时,系统会自动配置目标代理。使用 Google Cloud CLI 或 API 时,目标代理必须存在才能创建转发规则。您可以为给定代理使用多个转发规则。
IPProtocol
✔
此转发规则匹配的协议类型。支持的唯一值是 TCP。
loadBalancingScheme
✔
指定如何使用转发规则。Cloud Service Mesh 的有效值为 INTERNAL_SELF_MANAGED。
[[["易于理解","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-08-11。"],[],[],null,["# Forwarding rules for Cloud Service Mesh\n=======================================\n\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\nThis document applies only to Cloud Service Mesh with the load balancing APIs. We\nstrongly recommend that you use the\n[service routing APIs](/service-mesh/docs/service-routing/service-routing-overview)\nto deploy Cloud Service Mesh.\n\nCloud Service Mesh uses the forwarding rule to determine the target proxy to\nwhich traffic in the mesh is routed.\n\nEach forwarding rule provides a single global IPv4 address for a service. You\ncan use that address to create internal DNS records for your service\n(for example, by using a\n[Cloud DNS managed private zone](/dns/docs/zones#create-private-zone)).\nMetadata filters in the forwarding rule specify the criteria for which an\nxDS-compliant sidecar proxy receives the configuration.\n| **Note:** This page only discusses forwarding rules in the context of Cloud Service Mesh. Forwarding rules are also used to provide forwarding information in the control plane for [protocol forwarding](/load-balancing/docs/protocol-forwarding), [Classic VPN gateways](/network-connectivity/docs/vpn/concepts/overview#classic-vpn), and [Google Cloud load balancers](/load-balancing/docs/using-forwarding-rules). For a more comprehensive overview of forwarding rules, see the [Cloud Load Balancing forwarding rules overview](/load-balancing/docs/forwarding-rule-concepts).\n\nFor the Cloud Service Mesh control plane, the internal, self-managed, and\nglobal forwarding rule routes traffic by IP address, port, and protocol to a\ntarget proxy. The target proxy points to a URL map that contains rules that\ndetermine the destination of the traffic. The URL map also specifies the default\nbackend service. This backend service specifies a health check and determines\nthe appropriate backend, such as a managed instance group (MIG) that contains\nvirtual machine (VM) instances or a\n[network endpoint group (NEG)](/kubernetes-engine/docs/how-to/standalone-neg)\nthat contains Google Kubernetes Engine (GKE) backend Pods.\n\nThe following diagram shows how a forwarding rule fits into the Cloud Service Mesh\narchitecture.\n[](/static/service-mesh/docs/images/td-forwarding-rule.svg) Cloud Service Mesh forwarding rule highlighted (click to enlarge)\n\nForwarding rule properties\n--------------------------\n\nA forwarding rule resource contains the following properties that apply to\nCloud Service Mesh. The forwarding rule handles traffic that matches the\ndestination IP address, protocol, and port number.\n\nA `0.0.0.0` IP address in a forwarding rule is one of the options when\nusing Cloud Service Mesh. A `0.0.0.0` IP address means any IP address.\n\n- With a proxy deployment, a `0.0.0.0` IP address lets a proxy match any\n incoming traffic if no other specific match is found.\n\n- With a proxyless deployment, a `0.0.0.0` IP address provides a way to specify\n that an IP address is not required. More details follow about using\n `0.0.0.0` IP addresses with a target gRPC proxy.\n\nThe following table describes forwarding rule properties in more detail.\n\nAdd a global forwarding rule\n----------------------------\n\nTo learn how to configure a forwarding rule within the overall\nCloud Service Mesh setup with the load balancing APIS, see the following:\n\n- [Set up Cloud Service Mesh for Compute Engine VMs with automatic Envoy deployment](/service-mesh/legacy/load-balancing-apis/set-up-gce-vms-auto)\n- [Set up Cloud Service Mesh for Compute Engine VMs with manual Envoy deployment](/service-mesh/legacy/load-balancing-apis/set-up-gce-vms)\n- [Set up Cloud Service Mesh for GKE Pods with automatic Envoy injection](/service-mesh/legacy/load-balancing-apis/set-up-gke-pods-auto)\n- [Set up Cloud Service Mesh for GKE Pods with manual Envoy injection](/service-mesh/legacy/load-balancing-apis/set-up-gke-pods)\n- [Set up Cloud Service Mesh for Compute Engine VMs and proxyless gRPC services](/service-mesh/legacy/load-balancing-apis/set-up-proxyless-gce)\n- [Set up Cloud Service Mesh for GKE Pods and proxyless gRPC services](/service-mesh/legacy/load-balancing-apis/set-up-proxyless-gke)\n\nWhat's next\n-----------\n\n- To use metadata filters to control which sidecar proxies receive the configuration attached to the forwarding rule, see [Setting up config filtering based on `MetadataFilter` match](/service-mesh/legacy/load-balancing-apis/configure-advanced-traffic-management#config-filtering-metadata).\n- To route traffic, see [Cloud Service Mesh routing rule maps overview](/service-mesh/legacy/load-balancing-apis/routing-rule-maps).\n- To learn more about Cloud Service Mesh, see the [Cloud Service Mesh overview](/service-mesh/docs/overview)."]]