Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Configura il routing del traffico TCP
Questa guida mostra come utilizzare Cloud Service Mesh per instradare il traffico ai servizi
che gestiscono il traffico TCP. Questi servizi includono database, servizi VoIP e piattaforme di gestione, che prevedono di ricevere traffico TCP su porte o intervalli di porte specifici.
Configura un servizio che rappresenti una raccolta di backend o
endpoint identici che accettano richieste TCP dai client.
Configura una mappa delle regole di routing in modo che i proxy Envoy configurati da Cloud Service Mesh possano inviare richieste TCP.
I seguenti diagrammi mostrano come funziona il routing TCP rispettivamente per le istanze di macchine virtuali (VM) e i gruppi di endpoint di rete (NEG).
Configurazione di Cloud Service Mesh per TCP, backend Compute Engine (fai clic per ingrandire)
Configurazione di Cloud Service Mesh per backend TCP e NEG (fai clic per ingrandire)
preparazione
Questa guida si basa sulla guida alla preparazione di
Envoy per il service mesh
e presuppone che tu abbia già una comprensione di base del funzionamento di
Cloud Service Mesh.
La guida si concentra sugli aspetti della configurazione di Cloud Service Mesh diversi
quando configuri i servizi e il routing per il traffico TCP.
La guida presuppone che tu abbia già configurato un gruppo di istanze gestite (MIG) o
un NEG.
Configura le risorse di bilanciamento del carico
Per configurare le risorse di bilanciamento del carico:
Crea un controllo di integrità TCP
Configurazione con le VM
Se stai configurando i MIG, utilizza il seguente comando per creare un controllo di integrità globale; sostituisci PORT con il numero di porta TCP che questo controllo di integrità monitora:
La configurazione del servizio di backend per TCP con Cloud Service Mesh è leggermente diversa
dalla configurazione per HTTP. I seguenti passaggi acquisiscono queste differenze.
Configurazione con le VM
Se stai configurando i MIG, utilizza il seguente comando per creare un servizio di backend e aggiungere il controllo di integrità:
L'ultimo passaggio per configurare il servizio di backend è aggiungere i backend.
Poiché questo passaggio è la configurazione standard di Cloud Service Mesh (in altre
parole, nulla di specifico per i servizi basati su TCP), non viene mostrato qui.
Per saperne di più, consulta
Crea il servizio di backend
nella guida alla configurazione delle VM di Compute Engine con deployment Envoy automatico.
Configurazione con i NEG
Se stai configurando i NEG, utilizza i seguenti comandi per creare un servizio di backend e associare il controllo di integrità al servizio di backend:
L'ultimo passaggio per configurare il servizio di backend consiste nell'aggiungere il gruppo di backend. Poiché questo passaggio è la configurazione standard di Cloud Service Mesh (in altre
parole, nulla di specifico per i servizi basati su TCP), non viene mostrato qui.
Per maggiori informazioni, consulta
Creare il servizio di backend
nella guida alla configurazione dei pod GKE con l'inserimento automatico di Envoy.
Configura il routing per il servizio di backend basato su TCP
In questa sezione, creerai un proxy TCP di destinazione globale e una regola di forwarding globale.
Queste risorse consentono alle tue applicazioni di inviare traffico ai backend con i servizi di backend appena creati.
Considera quanto segue:
La regola di forwarding deve avere lo schema di bilanciamento del carico
INTERNAL_SELF_MANAGED.
L'indirizzo IP virtuale (VIP) e la porta che configuri nella regola di forwarding sono l'IP virtuale e la porta utilizzati dalle tue applicazioni quando inviano traffico ai tuoi servizi TCP. Puoi scegliere il VIP da una delle tue subnet.
Cloud Service Mesh utilizza questo VIP e questa porta per abbinare le richieste dei client a un
servizio di backend specifico.
Per informazioni su come le richieste client vengono abbinate ai servizi di backend, vedi
Service discovery.
gcloud
Utilizza il seguente comando per creare il proxy TCP di destinazione; sostituisci
BACKEND_SERVICE con il nome del servizio di backend
creato nel passaggio precedente. Nell'esempio seguente, utilizziamo
td-tcp-proxy come nome per il proxy TCP di destinazione, ma puoi scegliere
un nome adatto alle tue esigenze.
Crea la regola di forwarding. La regola di forwarding specifica l'IP virtuale e la porta utilizzati per abbinare le richieste client a un particolare servizio di backend. Per ulteriori informazioni, consulta
gcloud compute forwarding-rules create
nella guida di riferimento dei comandi gcloud.
A questo punto, Cloud Service Mesh è configurato per bilanciare il carico del traffico per
il VIP specificato nella regola di forwarding tra i backend.
Limitazioni
Non puoi configurare un criterio di sicurezza di Google Cloud Armor se utilizzi
il routing del traffico TCP.
Risoluzione dei problemi
Se le tue applicazioni tentano di inviare richieste ai tuoi servizi basati su TCP,
fai quanto segue:
Verifica che la porta del controllo di integrità TCP corrisponda alla porta su cui l'applicazione TCP prevede di ricevere il traffico del controllo di integrità.
Verifica che il nome della porta del servizio di backend corrisponda a quello specificato nel gruppo di istanze.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)"]]