Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Configurar o roteamento de tráfego TCP
Neste guia, demonstramos como usar o Cloud Service Mesh para rotear o tráfego a serviços
que gerenciam o tráfego TCP. Esses serviços incluem bancos de dados, serviços VOIP e
plataformas de gerenciamento, que esperam receber o tráfego TCP em portas ou intervalos de
porta específicos.
Configure um serviço que represente uma coleção de back-ends ou endpoints
idênticos que aceitam solicitações de TCP dos clientes.
Configure um mapa de regras de roteamento para que os proxies do Envoy configurados pelo Cloud Service Mesh
possam enviar solicitações TCP.
Os diagramas a seguir mostram como o roteamento TCP funciona para instâncias de máquina virtual (VM)
e grupos de endpoints de rede (NEGs, na sigla em inglês), respectivamente.
Como configurar o Cloud Service Mesh para TCP, back-ends do Compute Engine (clique para ampliar)
Como configurar o Cloud Service Mesh para back-ends de TCP e NEG (clique para ampliar)
Preparação
Este guia se baseia no guia de preparação
Envoy para malha de serviço
e pressupõe que você já tenha uma compreensão básica do
funcionamento do Cloud Service Mesh.
O guia se concentra em aspectos da configuração do Cloud Service Mesh que são diferentes
ao configurar os serviços e o roteamento para o tráfego TCP.
Para este guia, é necessário ter configurado um grupo gerenciado de instâncias (MIG, na sigla em inglês)
ou NEG.
Configurar recursos de balanceamento de carga
Siga as etapas abaixo para configurar os recursos de balanceamento de carga.
Crie uma verificação de integridade TCP
Configurar com VMs
Se você estiver configurando MIGs, use o seguinte comando para criar uma verificação
de integridade global. Substitua PORT pelo número da porta
TCP que esta verificação de integridade monitora:
A configuração do serviço de back-end para TCP com o Cloud Service Mesh é um pouco diferente
da configuração para HTTP. As etapas a seguir capturam essas diferenças.
Configurar com VMs
Se você estiver configurando MIGs, use o seguinte
comando para criar um serviço de back-end e adicionar a verificação de integridade:
A etapa final para configurar o serviço de back-end é adicionar os back-ends.
Como essa etapa é a configuração padrão do Cloud Service Mesh, ou seja,
nada específico dos serviços baseados em TCP, ela não é mostrada aqui.
Para mais informações, consulte
Criar o serviço de back-end
no guia de configuração das VMs do Compute Engine com implantação
automática do Envoy.
Configurar com NEGs
Se estiver configurando NEGs, use os seguintes comandos para criar um
serviço de back-end e associar a verificação de integridade a esse serviço:
A etapa final para configurar o serviço de back-end é adicionar o grupo de
back-end. Como essa etapa é a configuração padrão do Cloud Service Mesh, ou seja,
nada específico dos serviços baseados em TCP, ela não é mostrada aqui.
Para mais informações, consulte
Criar o serviço de back-end
no guia de configuração dos pods do GKE com injeção automática do Envoy.
Configurar o roteamento para seu serviço de back-end baseado em TCP
Nesta seção, mostramos como criar um
proxy TCP de destino
global e uma regra de encaminhamento global.
Esses recursos permitem que os aplicativos enviem tráfego para os back-ends com
os serviços de back-end recém-criados.
Considere o seguinte:
Sua regra de encaminhamento precisa ter o esquema de balanceamento de carga
INTERNAL_SELF_MANAGED
O endereço IP virtual (VIP, na sigla em inglês) e a porta que você configura na regra
de encaminhamento são o VIP e a porta que seus aplicativos usam ao enviar tráfego para
seus serviços TCP. É possível escolher o VIP de uma das suas sub-redes.
A Cloud Service Mesh usa esse VIP e essa porta para corresponder solicitações de clientes a um
determinado serviço de back-end.
Para informações sobre como as solicitações de cliente são correspondidas aos serviços de back-end, consulte
Descoberta de serviços.
gcloud
Use o seguinte comando para criar o proxy TCP de destino: substitua
BACKEND_SERVICE pelo nome do serviço de back-end
criado na etapa anterior. No exemplo a seguir, usamos
td-tcp-proxy como o nome do proxy TCP de destino, mas é possível escolher
um nome que atenda às suas necessidades.
Crie a regra de encaminhamento. A regra de encaminhamento especifica o VIP e a
porta usados ao corresponder solicitações de clientes a um determinado serviço de
back-end. Para mais informações, consulte
gcloud compute forwarding-rules create
na referência do comando gcloud.
Neste ponto, o Cloud Service Mesh está configurado para balancear a carga do tráfego do
VIP especificado na regra de encaminhamento dos back-ends.
Limitações
Não é possível configurar uma política de segurança do Google Cloud Armor se você estiver usando
o roteamento de tráfego TCP.
Solução de problemas
Se os aplicativos estiverem tentando enviar solicitações para os serviços baseados em TCP,
faça o seguinte:
Confirme se a porta de verificação de integridade TCP corresponde à porta em que o aplicativo
TCP espera receber o tráfego da verificação de integridade.
Confirme se o nome da porta do serviço de back-end corresponde ao especificado no
grupo de instâncias.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],null,["# Set up TCP traffic routing\n==========================\n\nThis guide demonstrates how you can use Cloud Service Mesh to route traffic to services\nthat handle TCP traffic. These services include databases, VOIP services, and\nmanagement platforms, which expect to receive TCP traffic on specific ports or\nport ranges.\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 guide applies to deployment with the older APIs. If you are using the new\nservice routing APIs, which are in preview, see\n[Cloud Service Mesh setup for TCP services with a `TCPRoute` resource](/service-mesh/docs/service-routing/set-up-tcp-route).\n\nUse this guide to do the following:\n\n- Set up a service that represents a collection of identical backends or endpoints that accept TCP requests from clients.\n- Set up a routing rule map so that Envoy proxies that Cloud Service Mesh configures can send TCP requests.\n\nThe following diagrams show how TCP routing works for virtual machine (VM)\ninstances and network endpoint groups (NEGs), respectively.\n[](/static/service-mesh/docs/images/td-tcp-gce.svg) Setting up Cloud Service Mesh for TCP, Compute Engine backends (click to enlarge)\n\n\u003cbr /\u003e\n\n\n[](/static/service-mesh/docs/images/td-tcp-neg.svg) Setting up Cloud Service Mesh for TCP, NEG backends (click to enlarge)\n\n\u003cbr /\u003e\n\nPreparation\n-----------\n\n- This guide builds on the [Envoy for service mesh](/service-mesh/docs/service-routing/prepare-for-envoy-setup) preparation guide, and assumes that you already have a basic understanding of how Cloud Service Mesh works.\n- The guide focuses on aspects of Cloud Service Mesh setup that are different when you configure your services and routing for TCP traffic.\n- The guide assumes that you have already set up a managed instance group (MIG) or NEG.\n\nConfigure load-balancing resources\n----------------------------------\n\nUse the following steps to configure the load-balancing resources.\n\n### Create a TCP health check\n\n### Setup with VMs\n\nIf you are configuring MIGs, use the following command to create a global\nhealth check; replace \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e with the TCP port\nnumber that this health check monitors: \n\n```\ngcloud compute health-checks create tcp td-vm-health-check \\\n --global \\\n --port=PORT\n```\n\n### Setup with NEGs\n\nIf you are configuring NEGs, use the following command to create a health\ncheck: \n\n```\ngcloud compute health-checks create tcp td-gke-health-check \\\n --use-serving-port\n```\n\nFor more information about health checks, see the following:\n\n- [Creating health checks](/load-balancing/docs/health-checks) in the Cloud Load Balancing documentation\n- [`gcloud compute health-checks create tcp`](/sdk/gcloud/reference/compute/health-checks/create/tcp) in the `gcloud` command reference\n\n### Create a firewall rule for your health check\n\nThis rule enables health checks from Google Cloud's health checkers to reach\nyour backends. \n\n### gcloud\n\n```\ngcloud compute firewall-rules create fw-allow-health-checks \\\n --action=ALLOW \\\n --direction=INGRESS \\\n --source-ranges=35.191.0.0/16,130.211.0.0/22 \\\n --target-tags=TAGS \\\n --rules=tcp:80\n```\n\nFor more information about firewall rules for health checks, see the following:\n\n- [Firewall rules for health checks](/load-balancing/docs/health-checks#fw-rule) in the Cloud Load Balancing documentation\n- [`gcloud compute firewall-rules create`](/sdk/gcloud/reference/compute/firewall-rules/create) in the `gcloud` command reference (includes guidance for \u003cvar translate=\"no\"\u003eTAGS\u003c/var\u003e)\n\n### Create a backend service for your TCP backends\n\nThe backend service setup for TCP with Cloud Service Mesh differs slightly\nfrom the setup for HTTP. The following steps capture those differences. \n\n### Setup with VMs\n\nIf you are configuring MIGs, use the following\ncommand to create a backend service and add the health check: \n\n```\n gcloud compute backend-services create td-vm-service \\\n --global \\\n --load-balancing-scheme=INTERNAL_SELF_MANAGED \\\n --health-checks=td-vm-health-check \\\n --protocol=TCP \\\n --global-health-checks\n```\n\nThe final step for setting up your backend service is to add your backends.\nBecause this step is standard Cloud Service Mesh setup (in other\nwords, nothing specific for TCP-based services), it is not shown here.\nFor more information, see\n[Create the backend service](/service-mesh/docs/service-routing/set-up-gce-vms-auto#creating_the_backend_service)\nin the setup guide for Compute Engine VMs with automatic Envoy\ndeployment.\n\n### Setup with NEGs\n\nIf you are configuring NEGs, use the following commands to create a\nbackend service and associate the health check with the backend service: \n\n```\ngcloud compute backend-services create td-gke-service \\\n --global \\\n --health-checks=td-gke-health-check \\\n --protocol=TCP \\\n --load-balancing-scheme=INTERNAL_SELF_MANAGED\n```\n\nThe final step for setting up your backend service is to add your backend\ngroup. Because this step is standard Cloud Service Mesh setup (in other\nwords, nothing specific for TCP-based services), it is not shown here.\nFor more information, see\n[Create the backend service](/service-mesh/legacy/load-balancing-apis/set-up-gke-pods-auto#creating_the_backend_service)\nin the setup guide for GKE Pods with automatic Envoy injection.\n\n### Set up routing for your TCP-based backend service\n\nIn this section, you create a global\n[target TCP proxy](/load-balancing/docs/tcp)\nand a global [forwarding rule](/load-balancing/docs/forwarding-rule-concepts).\nThese resources enable your applications to send traffic to the backends with\nyour newly created backend services.\n\nConsider the following:\n\n- Your forwarding rule must have the load-balancing scheme `INTERNAL_SELF_MANAGED`.\n- The virtual IP address (VIP) and port that you configure in the forwarding\n rule are the VIP and port that your applications use when sending traffic to\n your TCP services. You can choose the VIP from one of your subnets.\n Cloud Service Mesh uses this VIP and port to match client requests to a\n particular backend service.\n\n For information about how client requests are matched to backend services, see\n [Service discovery](/service-mesh/docs/traffic-management/service-discovery#service_discovery).\n\n### gcloud\n\n1. Use the following command to create the target TCP proxy; replace\n \u003cvar translate=\"no\"\u003eBACKEND_SERVICE\u003c/var\u003e with the name of the backend service\n created in the previous step. In the following example, we use\n `td-tcp-proxy` as the name for the target TCP proxy, but you can choose\n a name that suits your needs.\n\n ```\n gcloud compute target-tcp-proxies create td-tcp-proxy \\\n --backend-service=BACKEND_SERVICE\n ```\n | **Note:** Each service that requires a different VIP address must use a different forwarding rule.\n2. Create the forwarding rule. The forwarding rule specifies the VIP and\n port that are used when matching client requests to a particular backend\n service. For more information, see\n [`gcloud compute forwarding-rules create`](/sdk/gcloud/reference/compute/forwarding-rules/create)\n in the `gcloud` command reference.\n\n ```\n gcloud compute forwarding-rules create td-tcp-forwarding-rule \\\n --global \\\n --load-balancing-scheme=INTERNAL_SELF_MANAGED \\\n --address=VIP\\\n --target-tcp-proxy=td-tcp-proxy \\\n --ports=PORT \\\n --network=default\n ```\n\nAt this point, Cloud Service Mesh is configured to load balance traffic for\nthe VIP specified in the forwarding rule across your backends.\n\nLimitations\n-----------\n\nYou cannot configure a Google Cloud Armor security policy if you are using\nTCP traffic routing.\n\nTroubleshooting\n---------------\n\nIf your applications are attempting to send requests to your TCP-based services,\ndo the following:\n\n- Confirm that the TCP health check port matches the port on which the TCP application expects to receive health check traffic.\n- Confirm that the port name of the backend service matches what is specified in the instance group.\n\nWhat's next\n-----------\n\n- [Prepare to set up Cloud Service Mesh with Envoy](/service-mesh/docs/service-routing/prepare-for-envoy-setup)\n- [Troubleshoot Envoy deployments](/service-mesh/docs/service-routing/troubleshooting)"]]