Basculer entre une instance cible et un service de backend
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page explique comment basculer la cible d'une règle de transfert entre une instance cible et un service de backend.
Transfert de protocole externe
Pour basculer la cible d'une règle de transfert externe d'une instance cible vers un service de backend (ou inversement), vous devez supprimer et recréer la règle de transfert avec la nouvelle cible. Cette méthode nécessite une adresse IP statique si vous souhaitez utiliser la même adresse avec la nouvelle règle de transfert.
La suppression et la recréation de la règle de transfert sont le seul moyen de basculer entre le transfert de protocole externe et un équilibreur de charge réseau passthrough externe basé sur un service de backend.
Transfert de protocole interne
Il existe deux moyens de basculer entre le transfert de protocole interne et un équilibreur de charge réseau passthrough interne:
Vous pouvez basculer entre une instance cible et un service de backend en mettant à jour la règle de transfert avec la commande gcloud compute forwarding-rules set-target, comme décrit dans la section Modifier la cible d'une règle de transfert interne.
Lorsque vous passez du transfert de protocole interne à l'équilibreur de charge réseau passthrough interne, vous n'avez pas besoin de supprimer et de recréer la règle de transfert. La règle de transfert continue d'utiliser la même adresse IP interne (qu'elle soit statique ou éphémère).
Vous pouvez également basculer entre une instance cible et un service de backend en supprimant et en recréant la règle de transfert. Toutefois, cette méthode nécessite une adresse IPv4 statique pour pouvoir utiliser la même adresse avec la nouvelle règle de transfert.
Vous ne pouvez pas utiliser cette méthode pour les adresses IPv6, car la réservation d'une adresse IPv6 n'est pas acceptée.
Une instance cible ne spécifie aucun protocole. Elle hérite des protocoles et des ports de la règle de transfert. Par conséquent, lorsque vous changez de règle de transfert pour référencer un service de backend, vous devez vous assurer que le protocole IP de la règle de transfert (TCP ou UDP) correspond au protocole du service de backend (TCP ou UDP).
Le schéma suivant illustre un exemple utilisant le transfert de protocole interne.
Basculer entre une instance cible et un service de backend.
Modifier la cible d'une règle de transfert interne
Pour modifier une règle de transfert qui pointe vers une instance cible afin qu'elle pointe vers un service de backend régional, utilisez la commande suivante :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (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```"]]