Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En este paso, crearás un balanceador de cargas de aplicaciones para distribuir el tráfico a instancias de backend alojadas en Cloud Run.
En la configuración del balanceador de cargas, debes definir las reglas de enrutamiento, que determinan cómo el balanceador de cargas dirige el tráfico. Las reglas de enrutamiento incluyen reglas de host y coincidencias de rutas de acceso, que constituyen los componentes de configuración de un mapa de URL del balanceador de cargas de aplicaciones externo.
Ten en cuenta que, para completar este paso, debes tener un nombre de dominio válido o un certificado autoadministrado válido.
Crea un balanceador de cargas para el servicio de Cloud Run
En la Google Cloud consola, ve a la página Balanceo de cargas.
Selecciona la casilla de verificación Habilitar el redireccionamiento HTTP a HTTPS.
Haz clic en Listo.
Haz clic en Configuración de backend para configurarlo.
Configuración de backend
Haz clic en la lista Servicios y buckets de backend y, luego, ingresa los siguientes detalles:
Nombre: Ingresa gemini-streamlit-app-backend.
Tipo de backend: Haz clic en Grupo de extremos de red sin servidores.
Backends: En la tarjeta de Backend nuevo, realiza los siguientes pasos:
Haz clic en la lista Grupos de extremos de red sin servidores y, luego, en Crear grupo de extremos de red sin servidores.
Ingresa los siguientes detalles:
Nombre: Ingresa streamlit-app-neg.
Región: Selecciona us-central1.
Tipo de grupo de extremos de red sin servidores: Selecciona Cloud Run.
Seleccionar servicio: Selecciona el servicio de Cloud Run gemini-streamlit-cloudrun.
Haz clic en Crear.
Haz clic en Listo.
Desmarca la casilla de verificación Habilitar Cloud CDN.
En el cuadro Nombre de la política, ingresa default-security-policy-gemini-app-backend.
Haz clic en Crear y, luego, en Aceptar.
Haz clic en Reglas de enrutamiento para configurar las reglas de enrutamiento.
Reglas de enrutamiento
Haz clic en Regla avanzada de host y ruta de acceso.
En la sección Reglas de host y ruta de acceso, haz clic en (Predeterminada) Enrutar el tráfico al backend “” para cualquier host que no tenga coincidencia y, luego, ingresa los siguientes detalles:
Acción: Selecciona Enrutar el tráfico a un solo backend.
Backend: Selecciona gemini-streamlit-app-backend.
Haz clic en Listo.
Haz clic en Agregar regla de host y ruta de acceso para agregar una regla nueva.
En Nueva regla de host y ruta de acceso, ingresa los siguientes detalles:
Hosts: ingresa el nombre de dominio que se usó mientras creas el certificado administrado por Google.
Comparador de rutas de acceso: Copia la siguiente configuración del mapa de URL:
PROJECT_ID: El ID de tu proyecto de Google Cloud .
PRIORITY: Especifica la prioridad del servicio de backend con la que se evalúan las reglas de enrutamiento. En este caso, configúralo en cualquier valor porque solo creaste un servicio de backend.
Haz clic en Listo.
Haz clic en Revisar y finalizar para revisar la configuración y crear el balanceador de cargas.
Revisa y finaliza
Revisa la configuración del balanceador de cargas.
Para crear el balanceador de cargas, haz clic en Crear.
Agrega la dirección IP a los registros DNS del dominio
Actualiza los registros DNS del dominio a fin de que apunten a la dirección IP reservada que se creó para el balanceador de cargas. Es posible que debas comunicarte con el administrador de tu dominio para completar este paso.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[],[],null,["# Step 3: Create a load balancer\n\nIn this step, you create an [Application Load Balancer](/load-balancing/docs/application-load-balancer)\nto distribute the traffic to backend instances hosted on Cloud Run.\nIn the load balancer configuration, you define the routing rules, which\ndetermine how the load balancer directs the traffic. Routing rules include host\nrules and path matches, which constitute the configuration components of an external\nApplication Load Balancer's [URL map](/load-balancing/docs/url-map-concepts).\n\nNote that to complete this step, you must have a valid domain name or a\nvalid self-managed certificate.\n\nCreate a load balancer for the Cloud Run service\n------------------------------------------------\n\n1. In the Google Cloud console, go to the **Load balancing** page.\n\n [Go to Load balancing](https://console.cloud.google.com/net-services/loadbalancing/list/loadBalancers)\n2. Click **Create load balancer**.\n\n3. In the **Type of load balancer** section, click **Application Load Balancer (HTTP/HTTPS)** , and then click **Next**.\n\n4. In the **Public facing or internal** section, click **Public facing (external)** , and then click **Next**.\n\n5. In the **Global or single region deployment** section, click **Best for global workloads** , and then click **Next**.\n\n6. In the **Load balancer generation** section, click **Global external Application Load Balancer** , and then click **Next**.\n\n7. Click **Configure**.\n\n8. In the **Load Balancer name** field, enter `gemini-streamlit-app-lb`.\n\n9. Configure the load balancer by completing the **Frontend configuration** , **Backend configuration** , and **Routing rules** sections.\n\n### Frontend Configuration\n\n1. Specify the following **Frontend configuration**:\n\n - **Name** : Enter `gemini-streamlit-app-frontend`.\n\n - **Protocol** : Select **HTTPS (includes HTTP/2 and HTTP/3)**.\n\n - **Network Service Tier** : Set the **IP address** by [reserving a new external static IP address](/load-balancing/docs/https/setup-global-ext-https-serverless#ip-address). While reserving the new IP address, specify `genai-app-ip` as the **Name**.\n\n - **Certificate**: Perform the following steps to create a new Google-managed certificate:\n\n 1. Click **Create a new certificate**.\n\n 2. Specify the following details:\n\n - **Name** : Enter `my-genai-app-certificate`.\n\n - **Create mode** : Click **Create Google-managed certificate**.\n\n - **Domains**: Enter the domain name for provisioning the certificate.\n\n 3. Click **Create**.\n\n For more information about Google-managed SSL certificates, see\n [Use Google-managed SSL certificates](/load-balancing/docs/ssl-certificates/google-managed-certs).\n\n \u003c!-- --\u003e\n\n - Select the **Enable HTTP to HTTPS redirect** checkbox.\n2. Click **Done**.\n\n3. Click **Backend configuration** to configure the backend.\n\n### Backend configuration\n\n1. Click the **Backend services \\& backend buckets** list and then click\n CEnter the following details:\n\n - **Name** : Enter `gemini-streamlit-app-backend`.\n\n - **Backend type** : Click **Serverless network endpoint group**.\n\n - **Backends** : On the **New Backend** card, perform the following steps:\n\n 1. Click the **Serverless network endpoint groups** list, and then click **Create serverless network endpoint group**.\n\n 2. Enter the following details:\n\n - **Name** : Enter `streamlit-app-neg`.\n\n - **Region** : Select `us-central1`.\n\n - **Serverless network endpoint group type** : Select **Cloud Run**.\n\n - **Select service** : Select the `gemini-streamlit-cloudrun` Cloud Run service.\n\n 3. Click **Create**.\n\n 4. Click **Done**.\n\n2. Clear the **Enable Cloud CDN** checkbox.\n\n3. In the **Policy name** box, enter `default-security-policy-gemini-app-backend`.\n\n4. Click **Create** , and then click **OK**.\n\n5. Click **Routing rules** to configure the routing rules.\n\n### Routing rules\n\n1. Click **Advanced host and path rule**.\n\n2. In the **Host and path rules** section, click **(Default) Route traffic to backend \"\" for any unmatched hosts**, and then enter the following details:\n\n - **Action** : Select **Route traffic to a single backend**.\n\n - **Backend** : Select `gemini-streamlit-app-backend`.\n\n | **Note:** This rule handles the traffic for any unmatched host.\n3. Click **Done**.\n\n4. Click **Add host and path rule** to add a new rule.\n\n5. Under **New host and path rule**, enter the following details:\n\n - **Hosts**: Enter the domain name used while\n creating the Google-managed certificate.\n\n - **Path Matcher**: Copy the following URL map configuration:\n\n defaultService: projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/global/backendServices/gemini-streamlit-app-backend\n name: matcher1\n routeRules:\n - matchRules:\n - prefixMatch: /gemini-streamlit-app\n priority: \u003cvar translate=\"no\"\u003ePRIORITY\u003c/var\u003e\n routeAction:\n weightedBackendServices:\n - backendService: projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/global/backendServices/gemini-streamlit-app-backend\n weight: 100\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your Google Cloud project ID.\n\n - \u003cvar translate=\"no\"\u003ePRIORITY\u003c/var\u003e: Specify the priority of the backend service by\n which the route rules are evaluated. In this scenario, set this to any\n value because you created only one backend service.\n\n6. Click **Done**.\n\n7. Click **Review and finalize** to review the configuration and create the load balancer.\n\n### Review and finalize\n\n1. Review the load balancer configuration.\n\n2. To create the load balancer, click **Create**.\n\nAdd the IP address to the domain DNS records\n--------------------------------------------\n\nUpdate the DNS records of your domain to point to the reserved IP address that was\ncreated for your load balancer. You might have to contact the administrator\nof your domain to complete this step."]]