Cloud Service Mesh dan Traffic Director kini bergabung menjadi Cloud Service Mesh. Untuk mengetahui informasi selengkapnya, lihat ringkasan Cloud Service Mesh.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menyiapkan perutean traffic TCP
Panduan ini menunjukkan cara menggunakan Cloud Service Mesh untuk merutekan traffic ke layanan yang menangani traffic TCP. Layanan ini mencakup database, layanan VOIP, dan platform pengelolaan, yang mengharapkan untuk menerima traffic TCP pada port atau rentang port tertentu.
Siapkan layanan yang merepresentasikan kumpulan backend atau endpoint identik yang menerima permintaan TCP dari klien.
Siapkan peta aturan perutean sehingga proxy Envoy yang dikonfigurasi Cloud Service Mesh dapat mengirim permintaan TCP.
Diagram berikut menunjukkan cara kerja perutean TCP untuk instance mesin virtual (VM) dan grup endpoint jaringan (NEG).
Menyiapkan Cloud Service Mesh untuk TCP, backend Compute Engine (klik untuk memperbesar)
Menyiapkan Cloud Service Mesh untuk backend TCP, NEG (klik untuk memperbesar)
Persiapan
Panduan ini dibuat berdasarkan panduan persiapan
Envoy untuk service mesh, dan mengasumsikan bahwa Anda telah memiliki pemahaman dasar tentang cara kerja Cloud Service Mesh.
Panduan ini berfokus pada aspek penyiapan Cloud Service Mesh yang berbeda
saat Anda mengonfigurasi layanan dan perutean untuk traffic TCP.
Panduan ini mengasumsikan bahwa Anda telah menyiapkan grup instance terkelola (MIG) atau
NEG.
Mengonfigurasi resource load balancing
Gunakan langkah-langkah berikut untuk mengonfigurasi resource load balancing.
Membuat health check TCP
Penyiapan dengan VM
Jika Anda mengonfigurasi MIG, gunakan perintah berikut untuk membuat health check global; ganti PORT dengan nomor port TCP yang dipantau oleh health check ini:
Penyiapan layanan backend untuk TCP dengan Cloud Service Mesh sedikit berbeda
dengan penyiapan untuk HTTP. Langkah-langkah berikut mencakup perbedaan tersebut.
Penyiapan dengan VM
Jika Anda mengonfigurasi MIG, gunakan perintah berikut untuk membuat layanan backend dan menambahkan health check:
Langkah terakhir untuk menyiapkan layanan backend adalah menambahkan backend.
Karena langkah ini adalah penyiapan Cloud Service Mesh standar (dengan kata lain, tidak ada yang spesifik untuk layanan berbasis TCP), langkah ini tidak ditampilkan di sini.
Untuk mengetahui informasi selengkapnya, lihat
Membuat layanan backend
dalam panduan penyiapan untuk VM Compute Engine dengan deployment Envoy otomatis.
Penyiapan dengan NEG
Jika Anda mengonfigurasi NEG, gunakan perintah berikut untuk membuat layanan backend dan mengaitkan health check dengan layanan backend:
Langkah terakhir untuk menyiapkan layanan backend adalah menambahkan grup backend. Karena langkah ini adalah penyiapan Cloud Service Mesh standar (dengan kata lain, tidak ada yang spesifik untuk layanan berbasis TCP), langkah ini tidak ditampilkan di sini.
Untuk mengetahui informasi selengkapnya, lihat
Membuat layanan backend
dalam panduan penyiapan untuk Pod GKE dengan injeksi Envoy otomatis.
Menyiapkan pemilihan rute untuk layanan backend berbasis TCP
Di bagian ini, Anda akan membuat
proxy TCP target global
dan aturan penerusan global.
Resource ini memungkinkan aplikasi Anda mengirim traffic ke backend dengan layanan backend yang baru dibuat.
Pertimbangkan hal berikut:
Aturan penerusan Anda harus memiliki skema load balancing
INTERNAL_SELF_MANAGED.
Alamat IP virtual (VIP) dan port yang Anda konfigurasi dalam aturan penerusan adalah VIP dan port yang digunakan aplikasi Anda saat mengirim traffic ke layanan TCP Anda. Anda dapat memilih VIP dari salah satu subnet Anda.
Cloud Service Mesh menggunakan VIP dan port ini untuk mencocokkan permintaan klien dengan layanan backend tertentu.
Untuk mengetahui informasi tentang cara permintaan klien dicocokkan dengan layanan backend, lihat Penemuan layanan.
gcloud
Gunakan perintah berikut untuk membuat proxy TCP target; ganti
BACKEND_SERVICE dengan nama layanan backend yang
dibuat pada langkah sebelumnya. Dalam contoh berikut, kita menggunakan
td-tcp-proxy sebagai nama untuk proxy TCP target, tetapi Anda dapat memilih
nama yang sesuai dengan kebutuhan Anda.
Membuat aturan penerusan. Aturan penerusan menentukan VIP dan
port yang digunakan saat mencocokkan permintaan klien dengan layanan
backend tertentu. Untuk mengetahui informasi selengkapnya, lihat
gcloud compute forwarding-rules create
dalam referensi perintah gcloud.
Pada tahap ini, Cloud Service Mesh dikonfigurasi untuk melakukan load balancing traffic untuk VIP yang ditentukan dalam aturan penerusan di seluruh backend Anda.
Batasan
Anda tidak dapat mengonfigurasi kebijakan keamanan Google Cloud Armor jika menggunakan
perutean traffic TCP.
Pemecahan masalah
Jika aplikasi Anda mencoba mengirim permintaan ke layanan berbasis TCP, lakukan hal berikut:
Pastikan port health check TCP cocok dengan port tempat aplikasi TCP diharapkan menerima traffic health check.
Pastikan nama port layanan backend cocok dengan yang ditentukan di
grup instance.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 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)"]]