Beralih antara instance target dan layanan backend
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara mengalihkan target aturan penerusan antara
instance target dan layanan backend.
Penerusan protokol eksternal
Untuk mengalihkan target aturan penerusan eksternal dari instance target ke
layanan backend (atau sebaliknya), Anda harus menghapus dan membuat ulang
aturan penerusan dengan target baru. Metode ini memerlukan alamat IP statis
sehingga Anda dapat menggunakan alamat yang sama dengan aturan penerusan baru.
Menghapus dan membuat ulang aturan penerusan adalah satu-satunya cara untuk beralih antara penerusan protokol eksternal dan Load Balancer Jaringan passthrough eksternal berbasis layanan backend.
Penerusan protokol internal
Ada dua cara untuk beralih antara penerusan protokol internal dan
Load Balancer Jaringan passthrough internal:
Anda dapat beralih antara instance target dan layanan backend dengan memperbarui
aturan penerusan dengan perintah gcloud compute forwarding-rules set-target
seperti yang dijelaskan dalam
Mengubah target aturan penerusan internal.
Saat beralih antara penerusan protokol internal dan Load Balancer Jaringan passthrough internal, Anda tidak perlu menghapus dan membuat ulang aturan penerusan. Aturan penerusan akan terus menggunakan alamat IP internal yang sama (baik statis maupun sementara).
Anda juga dapat beralih antara instance target dan layanan backend dengan menghapus
dan membuat ulang aturan penerusan. Namun, metode ini memerlukan alamat IPv4 statis untuk menggunakan alamat yang sama dengan aturan penerusan baru.
Anda tidak dapat menggunakan metode ini untuk alamat IPv6 karena mencadangkan alamat IPv6 tidak didukung.
Instance target tidak menentukan protokol apa pun—instance mewarisi protokol dan port aturan penerusan. Oleh karena itu, saat mengalihkan aturan penerusan untuk mereferensikan layanan backend, Anda harus memastikan bahwa protokol IP aturan penerusan (TCP atau UDP) cocok dengan protokol layanan backend (TCP atau UDP).
Diagram berikut menunjukkan contoh yang menggunakan penerusan protokol internal.
Beralih antara instance target dan layanan backend.
Mengubah target aturan penerusan internal
Untuk mengubah aturan penerusan dari mengarah ke instance target menjadi mengarah ke layanan backend regional, gunakan perintah berikut:
[[["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,["# Switch between a target instance and a backend service\n\nThis page describes how to switch the target of a forwarding rule between a\ntarget instance and a backend service.\n\nExternal protocol forwarding\n----------------------------\n\nTo switch an external forwarding rule's target from a target instance to a\nbackend service (or the other way around), you need to delete and re-create\nthe forwarding rule with the new target. This method requires a static IP\naddress so that you can use the same address with the new forwarding rule.\n\nDeleting and re-creating the forwarding rule is the only way to switch between\nexternal protocol forwarding and a backend service-based external passthrough Network Load Balancer.\n\nInternal protocol forwarding\n----------------------------\n\nThere are two ways to switch between internal protocol forwarding and an\ninternal passthrough Network Load Balancer:\n\n- You can switch between a target instance and a backend service by updating the\n forwarding rule with the `gcloud compute forwarding-rules set-target` command\n as described in\n [Change the target of an internal forwarding rule](#int-change-target).\n When switching between\n internal protocol forwarding and an internal passthrough Network Load Balancer, you don't need\n to delete and re-create the forwarding rule. The forwarding rule continues to\n use the same internal IP address (whether static or ephemeral).\n\n- You can also switch between a target instance and a backend service by deleting\n and re-creating the forwarding rule. However, this method requires a static\n IPv4 address in order to use the same address with the new forwarding rule.\n You can't use this method for IPv6 addresses because reserving an IPv6 address\n is not supported.\n\nA target instance does not specify any protocol---it inherits the protocols and\nports of the forwarding rule. Therefore, when switching a forwarding rule to\nreference a backend service, you must ensure that the IP protocol of the\nforwarding rule (either TCP or UDP) matches the protocol of the backend\nservice (either TCP or UDP).\n\nThe following diagram shows an example that uses internal protocol forwarding.\n[](/static/load-balancing/images/pf-int-switch-target.svg) Switch between a target instance and a backend service.\n\n### Change the target of an internal forwarding rule\n\nTo change a forwarding rule from pointing to a target instance to pointing to a\nregional backend service, use the following command: \n\n```\ngcloud compute forwarding-rules set-target FORWARDING_RULE \\\n --backend-service=BACKEND_SERVICE \\\n --region=REGION\n```\n\nTo transition back to a target instance, use the following command: \n\n```\ngcloud compute forwarding-rules set-target FORWARDING_RULE \\\n --target-instance=TARGET_INSTANCE \\\n --target-instance-zone=ZONE\n```"]]