Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Au cours de cette étape, vous allez créer un équilibreur de charge d'application pour distribuer le trafic vers les instances backend hébergées sur Cloud Run.
Dans la configuration de l'équilibreur de charge, vous définissez les règles de routage, qui déterminent la manière dont l'équilibreur de charge dirige le trafic. Les règles de routage incluent les règles d'hôte et les correspondances de chemin d'accès, qui constituent les composants de configuration d'un mappage d'URL de l'équilibreur de charge d'application externe.
Notez que pour effectuer cette étape, vous devez disposer d'un nom de domaine ou d'un certificat autogéré valide.
Créer un équilibreur de charge pour le service Cloud Run
Dans Google Cloud Console, accédez à la page Équilibrage de charge.
Dans la section Type d'équilibreur de charge, cliquez sur Équilibreur de charge d'application (HTTP/HTTPS), puis sur Suivant.
Dans la section Public ou interne, cliquez sur Public (externe), puis sur Suivant.
Dans la section Déploiement mondial ou dans une seule région, cliquez sur Recommandé pour les charges de travail à l'échelle mondiale, puis sur Suivant.
Dans la section Génération de l'équilibreur de charge, cliquez sur Équilibreur de charge d'application externe global, puis sur Suivant.
Cliquez sur Configurer.
Dans le champ Nom de l'équilibreur de charge, saisissez gemini-streamlit-app-lb.
Configurez l'équilibreur de charge en complétant les sections Configuration de l'interface, Configuration du backend et Règles de routage.
Configuration de l'interface
Spécifiez la configuration de l'interface suivante :
Nom : saisissez gemini-streamlit-app-frontend.
Protocole : sélectionnez HTTPS (inclut HTTP/2 et HTTP/3).
Cochez la case Activer la redirection HTTP vers HTTPS.
Cliquez sur OK.
Cliquez sur Configuration du backend pour configurer le backend.
Configuration du backend
Cliquez sur la liste Services de backend et buckets backend, puis saisissez les informations suivantes :
Nom : saisissez gemini-streamlit-app-backend.
Type de backend : cliquez sur Groupe de points de terminaison du réseau sans serveur.
Backends : sur la carte Nouveau backend, procédez comme suit :
Cliquez sur la liste Groupes de points de terminaison du réseau sans serveur, puis sur Créer un groupe de points de terminaison du réseau sans serveur.
Saisissez les informations suivantes :
Nom : saisissez streamlit-app-neg.
Région : sélectionnez us-central1.
Type de groupe de points de terminaison du réseau sans serveur : sélectionnez Cloud Run.
Sélectionner un service : sélectionnez le service Cloud Run gemini-streamlit-cloudrun.
Cliquez sur Créer.
Cliquez sur OK.
Décochez la case Activer Cloud CDN.
Dans la zone Nom de la règle, saisissez default-security-policy-gemini-app-backend.
Cliquez sur Créer, puis sur OK.
Cliquez sur Règles de routage pour configurer les règles de routage.
Règles de routage
Cliquez sur Règle d'hôte et de chemin d'accès avancée.
Dans la section Règles d'hôte et de chemin d'accès, cliquez sur (Par défaut) Acheminer le trafic vers le backend "" pour les hôtes sans correspondance, puis saisissez les informations suivantes :
Action : sélectionnez Acheminer le trafic vers un backend unique.
PRIORITY : spécifiez la priorité du service de backend selon lequel les règles de routage sont évaluées. Dans ce scénario, définissez cette valeur sur n'importe quelle valeur, car vous avez créé un seul service de backend.
Cliquez sur OK.
Cliquez sur Vérification et finalisation pour vérifier la configuration et créer l'équilibreur de charge.
Vérifier et finaliser
Vérifiez la configuration de l'équilibreur de charge.
Pour créer l'équilibreur de charge, cliquez sur Créer.
Ajouter l'adresse IP aux enregistrements DNS du domaine
Mettez à jour les enregistrements DNS de votre domaine pour qu'ils pointent vers l'adresse IP réservée créée pour votre équilibreur de charge. Vous devrez peut-être contacter l'administrateur de votre domaine pour effectuer cette étape.
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 2024/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 2024/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."]]