Quando crei il bilanciatore del carico, puoi registrarlo come endpoint in un servizio e uno spazio dei nomi Service Directory esistenti a tua scelta. Le applicazioni client possono quindi utilizzare Service Directory (utilizzando HTTP o gRPC) per risolvere l'indirizzo del servizio bilanciatore del carico di rete passthrough esterno e connettersi direttamente.
Autorizzazioni richieste per questa attività
Per eseguire questa attività, devi disporre delle seguenti autorizzazioni
e dei seguenti ruoli IAM.
Autorizzazioni
servicedirectory.endpoints.create
servicedirectory.endpoints.delete
Ruoli
roles/compute.networkAdmin
roles/compute.securityAdmin
roles/compute.instanceAdmin
Limitazioni
L'integrazione di Service Directory con i bilanciatori del carico di rete passthrough esterni presenta le seguenti limitazioni:
La registrazione automatica supporta solo i bilanciatori del carico di livello 4 esterni. Puoi registrarti
i servizi di bilanciamento del carico di Google Kubernetes Engine utilizzando
l'integrazione GKE. Puoi registrare altri bilanciatori del carico esterni, bilanciatori del carico globali, ingressi e gateway di Google Kubernetes Engine chiamando l'API Directory Service.
Puoi utilizzare la registrazione automatica solo al momento della creazione della regola di inoltro. La registrazione automatica mediante l'aggiornamento di Google Cloud CLI per una regola di inoltro già esistente non è disponibile.
Service Directory non fornisce connettività, il che significa che, anche se Service Directory memorizza l'indirizzo IP virtuale del bilanciatore del carico di rete passthrough esterno, la ricerca del bilanciatore del carico di rete passthrough esterno in Service Directory non garantisce che puoi connetterti all'indirizzo IP virtuale.
Prima di iniziare
Queste istruzioni richiedono quanto segue:
Devi già avere uno spazio dei nomi e un servizio Service Directory.
In caso contrario, crea uno spazio dei nomi e un servizio utilizzando la procedura descritta in Configurare Service Directory.
Lo spazio dei nomi e il servizio Service Directory devono trovarsi nello stesso progetto e nella stessa regione della regola di inoltro del bilanciatore del carico di rete passthrough esterno che stai creando.
Devi aver già configurato le risorse necessarie per creare una regola di inoltro del bilanciatore del carico di rete passthrough esterno.
Configura le regole di inoltro per registrare un bilanciatore del carico di rete passthrough esterno in Service Directory
Devi configurare una regola di inoltro per registrare il bilanciatore del carico di rete passthrough esterno in Service Directory. Per registrare un bilanciatore del carico di rete passthrough esterno, consulta la sezione seguente.
Registra un bilanciatore del carico di rete passthrough esterno
FORWARDING_RULE_NAME: un nome per la regola di inoltro
che vuoi creare
REGION: la regione in cui creare la regola di inoltro
RESERVED_IP_ADDRESS: l'indirizzo IP a cui si applica la regola di inoltro
PROTOCOL_TYPE: il protocollo IP a cui deve essere applicata la regola
PORT_NUMBER: un elenco di porte separate da virgole
BACKEND_SERVICE_NAME: il servizio di backend di destinazione che
riceve il traffico
SD_SERVICE_NAME: il nome completo del servizio Directory dei servizi in cui vuoi registrare l'endpoint. Questo servizio deve trovarsi nello stesso progetto e nella stessa regione della regola di inoltro in fase di creazione.
Ad esempio:
projects/PROJECT/locations/REGION/namespaces/NAMESPACE_NAME/services/SERVICE_NAME.
Verificare l'endpoint
Gli endpoint di Service Directory creati quando registri un bilanciatore del carico di rete passthrough esterno hanno le seguenti caratteristiche:
L'endpoint ha lo stesso nome della regola di inoltro con il numero di porta specificato (<forwarding rule name>-<port>). Ad esempio, se crei una regola di inoltro RULE con --port=8080, ottieni un endpoint denominato RULE-8080. Per la stessa regola, se hai specificato due porte --port=8080, 8081,
ottieni due endpoint, RULE-8080 e RULE-8081. Se specifichi --port=ALL,
l'endpoint di Service Directory è registrato con la porta 0. Se sei il proprietario del bilanciatore del carico di rete passthrough esterno, devi assicurarti che chi chiama l'API sappia su quale porta connettersi.
Non puoi modificare o eliminare l'endpoint utilizzando l'API Directory
Service pubblica. L'endpoint viene eliminato automaticamente solo quando elimini la regola di inoltro. Ciò significa che non puoi eliminare il servizio e lo spazio dei nomi in cui risiede l'endpoint finché esiste la regola di inoltro.
L'endpoint stesso non viene fatturato, anche se a qualsiasi chiamata API all'endpoint si applicano i normali dettagli dei prezzi.
Per confermare che l'endpoint è stato creato, risolvi il servizio in Service Directory.
Dovresti vedere un endpoint con lo stesso nome della regola di inoltro con il numero di porta specificato.
Per verificare che l'eliminazione della regola di inoltro abbia eliminato automaticamente l'endpoint da Service Directory, esegui il comando gcloud service-directory
services resolve descritto nella sezione Verificare l'endpoint del servizio Service Directory.
Per eliminare lo spazio dei nomi e il servizio Service Directory, consulta Eliminare le risorse.
Per trovare soluzioni ai problemi comuni che potresti riscontrare durante l'utilizzo di Service Directory, consulta la sezione Risoluzione dei problemi.
[[["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,["# Register an external passthrough Network Load Balancer\n\nThis page provides information about how to configure an\n[external passthrough Network Load Balancer](/load-balancing/docs/network) so that it is automatically\nregistered in Service Directory.\n\nWhen you create your load balancer, you can register it as an endpoint in an\nexisting Service Directory namespace and service of your choice. Client\napplications can then use Service Directory (using HTTP or gRPC) to resolve\nthe address of the external passthrough Network Load Balancer service and connect to it\ndirectly.\n\n#### Permissions required for this task\n\nTo perform this task, you must have been granted the following permissions\n*and* IAM roles.\n\n**Permissions**\n\n- `servicedirectory.endpoints.create`\n- `servicedirectory.endpoints.delete`\n\n**Roles**\n\n- `roles/compute.networkAdmin`\n- `roles/compute.securityAdmin`\n- `roles/compute.instanceAdmin`\n\nLimitations\n-----------\n\nService Directory integration with external passthrough Network Load Balancers has the following\nlimitations:\n\n- Automatic registration only supports external Layer 4 load balancers. You can register Google Kubernetes Engine load balancing services using the [GKE\n integration](/service-directory/docs/configuring-sd-for-gke). You can register other external load balancers, global load balancers, and Google Kubernetes Engine ingresses and gateways by calling the [Service Directory\n API](/service-directory/docs/apis).\n- You can use automatic registration only at the time of forwarding rule creation. Automatic registration using Google Cloud CLI update for an already existing forwarding rule is not available.\n- Service Directory does not provide connectivity, which means that although Service Directory stores the virtual IP address of the external passthrough Network Load Balancer, looking up the external passthrough Network Load Balancer in Service Directory does not guarantee that you can connect to the virtual IP address.\n\nBefore you begin\n----------------\n\nThese instructions require the following:\n\n- You must already have a Service Directory namespace and service in place.\n If you do not, create a namespace and service using\n the procedure in [Configure Service Directory](/service-directory/docs/configuring-service-directory).\n\n The Service Directory namespace and service must be in the\n same project and region as the external passthrough Network Load Balancer forwarding rule that\n you are creating.\n- You must already have set up the necessary\n resources to create an external passthrough Network Load Balancer forwarding rule.\n\n For information about how to create an external passthrough Network Load Balancer, see [Setting up a\n external passthrough Network Load Balancer](/load-balancing/docs/network/setting-up-network-backend-service).\n\nSet up forwarding rules to register an external passthrough Network Load Balancer in Service Directory\n------------------------------------------------------------------------------------------------------\n\nYou must set up a forwarding rule to register the external passthrough Network Load Balancer in\nService Directory. To register an external passthrough Network Load Balancer, see the following section.\n\n### Register an external passthrough Network Load Balancer\n\nTo register an external passthrough Network Load Balancer, run the [`gcloud compute forwarding-rules\ncreate` command](/sdk/gcloud/reference/compute/forwarding-rules/create) and\nset the `service-directory-registration` flag: \n\n```\ngcloud beta compute forwarding-rules create FORWARDING_RULE_NAME \\\n --region=REGION \\\n --load-balancing-scheme=EXTERNAL \\\n --address=RESERVED_IP_ADDRESS \\\n --ip-protocol=PROTOCOL_TYPE \\\n --ports=PORT_NUMBER \\\n --backend-service=BACKEND_SERVICE_NAME \\\n --backend-service-region=REGION \\\n --service-directory-registration=SD_SERVICE_NAME\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFORWARDING_RULE_NAME\u003c/var\u003e: a name for the forwarding rule that you want to create\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region to create the forwarding rule in\n- \u003cvar translate=\"no\"\u003eRESERVED_IP_ADDRESS\u003c/var\u003e: the IP address that the forwarding rule serves\n- \u003cvar translate=\"no\"\u003ePROTOCOL_TYPE\u003c/var\u003e: the IP protocol that the rule is to serve\n- \u003cvar translate=\"no\"\u003ePORT_NUMBER\u003c/var\u003e: a list of comma-separated ports\n- \u003cvar translate=\"no\"\u003eBACKEND_SERVICE_NAME\u003c/var\u003e: the target backend service that receives the traffic\n- \u003cvar translate=\"no\"\u003eSD_SERVICE_NAME\u003c/var\u003e: the fully qualified name of the Service Directory service where you want to register the endpoint. This service must be in the same project and region as the forwarding rule being created. For example: projects/\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/namespaces/\u003cvar translate=\"no\"\u003eNAMESPACE_NAME\u003c/var\u003e/services/\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e.\n\n### Verify the endpoint\n\nThe Service Directory endpoints that are created when you register\nan external passthrough Network Load Balancer have the following characteristics:\n\n- The endpoint has the same name as the name of the forwarding rule with the specified port number (`\u003cforwarding rule name\u003e-\u003cport\u003e`). For example, if you create a forwarding rule `RULE` with `--port=8080`, you get an endpoint called `RULE-8080`. For the same rule, if you specified two ports `--port=8080, 8081`, you get two endpoints, `RULE-8080` and `RULE-8081`. If you specify `--port=ALL`, the Service Directory endpoint is registered with port `0`. If you are the owner of the external passthrough Network Load Balancer, you must ensure that the API caller knows what port to connect on.\n- You cannot modify or delete the endpoint using the public Service Directory API. Only when you delete the forwarding rule does the endpoint get automatically deleted. This means that you cannot delete the service and namespace that the endpoint resides in while the forwarding rule exists.\n- The endpoint itself is not billed, although normal pricing details apply to any API calls to the endpoint.\n\nTo confirm that the endpoint is created, resolve the service in Service Directory.\nYou should see an endpoint with the same name as the name of the\nforwarding rule with the specified port number.\n\nTo resolve the service in Service Directory, run the [`gcloud service-directory\nservices resolve`](/sdk/gcloud/reference/service-directory/services/resolve)\ncommand: \n\n```\ngcloud service-directory services resolve SD_SERVICE_NAME \\\n --namespace=SD_NAMESPACE_NAME \\\n --location=REGION\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSD_SERVICE_NAME\u003c/var\u003e: the name of the Service Directory service to resolve. It must live in the Service Directory namespace name.\n- \u003cvar translate=\"no\"\u003eSD_NAMESPACE_NAME\u003c/var\u003e: the name that you gave the namespace containing your service.\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the Google Cloud region containing the namespace. This should be the same as the region that you created the forwarding rule in.\n\nCleanup\n-------\n\nTo delete the resources that you created, follow these steps.\n\n1. To delete the forwarding rule, run the [`gcloud compute forwarding-rules\n delete`](/sdk/gcloud/reference/compute/forwarding-rules/delete)\n command:\n\n ```\n gcloud compute forwarding-rules delete FORWARDING_RULE_NAME \\\n --region=REGION\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eFORWARDING_RULE_NAME\u003c/var\u003e: the name of the forwarding rule that you created\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region for the forwarding rule\n\n For further details, see [Deleting a forwarding\n rule](/load-balancing/docs/using-forwarding-rules#deleting-fr).\n\n To confirm that deleting the forwarding rule has automatically deleted the\n endpoint from Service Directory, run the [`gcloud service-directory\n services resolve`](/sdk/gcloud/reference/service-directory/services/resolve)\n command described in [Verify the endpoint](#verify-endpoint)\n section on your Service Directory service.\n2. To delete the Service Directory namespace and service, see [Delete\n resources](/service-directory/docs/configuring-service-directory#delete_resources).\n\nWhat's next\n-----------\n\n- To get an overview of Service Directory, see the [Service Directory overview](/service-directory/docs/overview).\n- To find solutions for common issues that you might encounter when using Service Directory, see [Troubleshooting](/service-directory/docs/troubleshooting)."]]