Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Tester l'équilibreur de charge TCP interne
Créer une VM cliente
Cet exemple crée une VM cliente dans la même région que les backends. Envoyez ensuite du trafic depuis le client vers l'équilibreur de charge.
La VM cliente peut se trouver dans n'importe quelle zone de la même région que l'équilibreur de charge, et utiliser n'importe quel sous-réseau de cette région.
Console
Dans la console Google Cloud , accédez à la page Instances de VM.
ZONE : zone de la VM cliente. Cette zone doit se trouver dans la même région que l'équilibreur de charge.
SUBNET : sous-réseau de la VM cliente.
Envoyer du trafic IPv6 à l'équilibreur de charge
Maintenant que vous avez configuré votre équilibreur de charge, vous pouvez tester votre déploiement en envoyant du trafic vers son adresse IP. La propagation de la configuration de l'équilibreur de charge peut prendre quelques minutes après son premier déploiement.
Connectez-vous à l'instance de VM cliente.
gcloud compute ssh CLIENT_VM_NAME \
--zone=ZONE
Remplacez les éléments suivants :
CLIENT_VM_NAME : nom de la VM cliente.
ZONE : zone de la VM cliente.
Obtenez l'adresse IP de l'équilibreur de charge.
Pour obtenir l'adresse IPv6, utilisez la commande suivante.
Envoyer du trafic IPv4 vers l'équilibreur de charge
Maintenant que vous avez configuré votre équilibreur de charge, vous pouvez tester votre déploiement en envoyant du trafic vers son adresse IP. La propagation de la configuration de l'équilibreur de charge peut prendre quelques minutes après son premier déploiement.
Connectez-vous à l'instance de VM cliente.
gcloud compute ssh CLIENT_VM_NAME \
--zone=ZONE
Remplacez les éléments suivants :
CLIENT_VM_NAME : nom de la VM cliente.
ZONE : zone de la VM cliente.
Obtenez l'adresse IP de l'équilibreur de charge.
Pour obtenir l'adresse IPv4, utilisez la commande suivante.
Remplacez IPV4_FORWARDING_RULE_NAME par le nom de la règle de transfert IPv4.
Envoyez du trafic vers l'équilibreur de charge.
À partir de clients disposant d'une connectivité IPv4, exécutez la commande suivante:
curl -m 10 -s http://LB_IPV4_ADDRESS:80
Remplacez LB_IPV4_ADDRESS par l'adresse IPv4 de l'équilibreur de charge.
Tester l'équilibreur de charge TCP externe
Envoyer du trafic IPv6 à l'équilibreur de charge
Maintenant que vous avez configuré votre équilibreur de charge, vous pouvez tester votre déploiement en envoyant du trafic vers son adresse IP. La propagation de la configuration de l'équilibreur de charge peut prendre quelques minutes après son premier déploiement.
Obtenez l'adresse IP de l'équilibreur de charge.
Pour obtenir l'adresse IPv6, utilisez la commande suivante.
Remplacez IPV6_FORWARDING_RULE_NAME par le nom de la règle de transfert IPv6.
Envoyez du trafic vers votre équilibreur de charge à l'aide de curl pour contacter son adresse IP.
À partir de clients disposant d'une connectivité IPv6, exécutez la commande suivante:
while true; do curl -m1 http://LB_IPV6_ADDRESS; done
Remplacez LB_IPV6_ADDRESS par l'adresse IPv6 de l'équilibreur de charge.
Par exemple, si l'adresse IPv6 attribuée est [2001:db8:1:1:1:1:1:1/96]:80, la commande se présente comme suit :
while true; do curl -m1 http://[2001:db8:1:1:1:1:1:1]:80; done
Notez le texte renvoyé par la commande curl. Le nom de la VM de backend qui génère la réponse est affiché dans ce texte, par exemple : Page served
from: VM_NAME.
La réponse de la commande curl est alternée de manière aléatoire entre les instances de backend. En cas d'échec au début de la phase de réponse, il vous faudra probablement patienter environ 30 secondes pour que la configuration soit entièrement chargée et que vos instances soient identifiées comme saines avant de réessayer :
Envoyer du trafic IPv4 vers l'équilibreur de charge
Maintenant que vous avez configuré votre équilibreur de charge, vous pouvez tester votre déploiement en envoyant du trafic vers son adresse IP. La propagation de la configuration de l'équilibreur de charge peut prendre quelques minutes après son premier déploiement.
Obtenez l'adresse IP de l'équilibreur de charge.
Pour obtenir l'adresse IPv4, utilisez la commande suivante.
Remplacez IPV4_FORWARDING_RULE_NAME par le nom de la règle de transfert IPv4.
Envoyez du trafic vers votre équilibreur de charge à l'aide de curl pour contacter son adresse IP.
À partir de clients disposant d'une connectivité IPv4, exécutez la commande suivante:
while true; do curl -m1 LB_IPV4_ADDRESS; done
Remplacez LB_IPV4_ADDRESS par l'adresse IPv4 de l'équilibreur de charge.
Notez le texte renvoyé par la commande curl. Le nom de la VM de backend qui génère la réponse est affiché dans ce texte, par exemple : Page served
from: VM_NAME.
La réponse de la commande curl est alternée de manière aléatoire entre les instances de backend. En cas d'échec au début de la phase de réponse, il vous faudra probablement patienter environ 30 secondes pour que la configuration soit entièrement chargée et que vos instances soient identifiées comme saines avant de réessayer :
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,["# Test shared how-to NetLB test modules\n\nTest internal TCP LB\n--------------------\n\n### Create client VM\n\nThis example creates a client VM in the same region as the backends. You then\nsend traffic from the client to the load balancer.\n\nThe client VM can be in any zone in the same region as the load balancer, and it\ncan use any subnet in that region. \n\n### Console\n\n1. In the Google Cloud console, go to the **VM instances** page.\n\n [Go to VM instances](https://console.cloud.google.com/compute/instances)\n2. Click **Create instance**.\n\n3. In the **Name** field, enter a name.\n\n4. For **Region**, select the same region as the load balancer.\n\n5. For **Zone**, select a zone.\n\n6. Click **Networking**.\n\n7. Configure the following fields and click **Done**:\n\n - For **Network tags** , enter `allow-ssh`.\n - For **Network interfaces**, select a network and a subnet. You can use the same network and subnet as the backends.\n - For **IP stack type** , choose **IPv6 (single-stack)**.\n8. Click **Create**.\n\n### gcloud\n\n```\ngcloud compute instances create CLIENT_VM_NAME \\\n --zone=ZONE \\\n --image-family=debian-12 \\\n --image-project=debian-cloud \\\n --stack-type=IPV6_ONLY \\\n --tags=allow-ssh \\\n --subnet=SUBNET\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eCLIENT_VM_NAME\u003c/var\u003e: the name of the client VM.\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone for the client VM. This zone must be in the same region as the load balancer.\n- \u003cvar translate=\"no\"\u003eSUBNET\u003c/var\u003e: the subnet for the client VM.\n\n### Send IPv6 traffic to the load balancer\n\nNow that you have configured your load balancer, you can test your deployment by\nsending traffic to the load balancer's IP address. It might take a few minutes\nfor the load balancer configuration to propagate after you first deploy it.\n\n1. Connect to the client VM instance.\n\n ```\n gcloud compute ssh CLIENT_VM_NAME \\\n --zone=ZONE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCLIENT_VM_NAME\u003c/var\u003e: the name of the client VM.\n - \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone of the client VM.\n2. Get the IP address of the load balancer.\n\n To get the IPv6 address, use the following command. \n\n ```\n gcloud compute forwarding-rules describe IPV6_FORWARDING_RULE_NAME \\\n --region=REGION\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIPV6_FORWARDING_RULE_NAME\u003c/var\u003e with the name of the\n IPv6 forwarding rule.\n3. Send traffic to the load balancer.\n\n From clients with IPv6 connectivity, run the following command: \n\n ```\n curl -m 10 -s http://LB_IPV6_ADDRESS:80\n ```\n\n Replace \u003cvar translate=\"no\"\u003eLB_IPV6_ADDRESS\u003c/var\u003e with the IPv6 address of the\n load balancer.\n\n For example, if the assigned IPv6 address is\n `[fd20:1db0:b882:802:0:46:0:0/96]:80`, the command should look like: \n\n ```\n curl -m 10 -s http://[fd20:1db0:b882:802:0:46:0:0]:80\n ```\n\n### Send IPv4 traffic to the load balancer\n\nNow that you have configured your load balancer, you can test your deployment by\nsending traffic to the load balancer's IP address. It might take a few minutes\nfor the load balancer configuration to propagate after you first deploy it.\n\n1. Connect to the client VM instance.\n\n ```\n gcloud compute ssh CLIENT_VM_NAME \\\n --zone=ZONE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCLIENT_VM_NAME\u003c/var\u003e: the name of the client VM.\n - \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone of the client VM.\n2. Get the IP address of the load balancer.\n\n To get the IPv4 address, use the following command. \n\n ```\n gcloud compute forwarding-rules describe IPV4_FORWARDING_RULE_NAME \\\n --region=REGION\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIPV4_FORWARDING_RULE_NAME\u003c/var\u003e with the name of the\n IPv4 forwarding rule.\n3. Send traffic to the load balancer.\n\n From clients with IPv4 connectivity, run the following command: \n\n ```\n curl -m 10 -s http://LB_IPV4_ADDRESS:80\n ```\n\n Replace \u003cvar translate=\"no\"\u003eLB_IPV4_ADDRESS\u003c/var\u003e with the IPv4 address of the\n load balancer.\n\nTest external TCP LB\n--------------------\n\n### Send IPv6 traffic to the load balancer\n\nNow that you have configured your load balancer, you can test your deployment by\nsending traffic to the load balancer's IP address. It might take a few minutes\nfor the load balancer configuration to propagate after you first deploy it.\n\n1. Get the load balancer's IP address.\n\n To get the IPv6 address, use the following command. \n\n ```\n gcloud compute forwarding-rules describe IPV6_FORWARDING_RULE_NAME \\\n --region=REGION\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIPV6_FORWARDING_RULE_NAME\u003c/var\u003e with the name of the\n IPv6 forwarding rule.\n2. Send traffic to your load balancer by using `curl` to contact its IP\n address.\n\n From clients with IPv6 connectivity, run the following command: \n\n ```\n while true; do curl -m1 http://LB_IPV6_ADDRESS; done\n ```\n\n Replace \u003cvar translate=\"no\"\u003eLB_IPV6_ADDRESS\u003c/var\u003e with the IPv6 address of the\n load balancer.\n\n For example, if the assigned IPv6 address is\n `[2001:db8:1:1:1:1:1:1/96]:80`, the command is similar to the following: \n\n ```\n while true; do curl -m1 http://[2001:db8:1:1:1:1:1:1]:80; done\n ```\n\n Note the text returned by the `curl` command. The name of the backend VM\n generating the response is displayed in that text; for example: `Page served\n from: `\u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e.\n\n The response from the `curl` command alternates randomly among the backend\n instances. If your response is initially unsuccessful, you might need to wait\n approximately 30 seconds for the configuration to be fully loaded and for\n your instances to be marked healthy before trying again.\n\n### Send IPv4 traffic to the load balancer\n\nNow that you have configured your load balancer, you can test your deployment by\nsending traffic to the load balancer's IP address. It might take a few minutes\nfor the load balancer configuration to propagate after you first deploy it.\n\n1. Get the load balancer's IP address.\n\n To get the IPv4 address, use the following command. \n\n ```\n gcloud compute forwarding-rules describe IPV4_FORWARDING_RULE_NAME \\\n --region=REGION\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIPV4_FORWARDING_RULE_NAME\u003c/var\u003e with the name of the\n IPv4 forwarding rule.\n2. Send traffic to your load balancer by using `curl` to contact its IP\n address.\n\n From clients with IPv4 connectivity, run the following command: \n\n ```\n while true; do curl -m1 LB_IPV4_ADDRESS; done\n ```\n\n Replace \u003cvar translate=\"no\"\u003eLB_IPV4_ADDRESS\u003c/var\u003e with the IPv4 address of the\n load balancer.\n\n Note the text returned by the `curl` command. The name of the backend VM\n generating the response is displayed in that text; for example: `Page served\n from: `\u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e.\n\n The response from the `curl` command alternates randomly among the backend\n instances. If your response is initially unsuccessful, you might need to wait\n approximately 30 seconds for the configuration to be fully loaded and for\n your instances to be marked healthy before trying again."]]