Step 3: Create a load balancer Stay organized with collections Save and categorize content based on your preferences.
In this step, you create anApplication Load Balancerto distribute the traffic to backend instances hosted on Cloud Run.In the load balancer configuration, you define the routing rules, whichdetermine how the load balancer directs the traffic. Routing rules include hostrules and path matches, which constitute the configuration components of an externalApplication Load Balancer'sURL map.
Note that to complete this step, you must have a valid domain name or avalid self-managed certificate.
Create a load balancer for the Cloud Run service
In the Google Cloud console, go to theLoad balancing page.
ClickCreate load balancer.
In theType of load balancer section, clickApplication Load Balancer (HTTP/HTTPS), and then clickNext.
In thePublic facing or internal section, clickPublic facing (external), and then clickNext.
In theGlobal or single region deployment section, clickBest for global workloads, and then clickNext.
In theLoad balancer generation section, clickGlobal external Application Load Balancer, and then clickNext.
ClickConfigure.
In theLoad Balancer name field, enter
gemini-streamlit-app-lb.Configure the load balancer by completing theFrontend configuration,Backend configuration, andRouting rules sections.
Frontend Configuration
Specify the followingFrontend configuration:
Name: Enter
gemini-streamlit-app-frontend.Protocol: SelectHTTPS (includes HTTP/2 and HTTP/3).
Network Service Tier: Set theIP address byreserving a new external static IP address. While reserving the new IP address, specify
genai-app-ipas theName.Certificate: Perform the following steps to create a new Google-managed certificate:
ClickCreate a new certificate.
Specify the following details:
Name: Enter
my-genai-app-certificate.Create mode: ClickCreate Google-managed certificate.
Domains: Enter the domain name for provisioning the certificate.
ClickCreate.
For more information about Google-managed SSL certificates, seeUse Google-managed SSL certificates.
- Select theEnable HTTP to HTTPS redirect checkbox.
ClickDone.
ClickBackend configuration to configure the backend.
Backend configuration
Click theBackend services & backend buckets list and then clickCEnter the following details:
Name: Enter
gemini-streamlit-app-backend.Backend type: ClickServerless network endpoint group.
Backends: On theNew Backend card, perform the following steps:
Click theServerless network endpoint groups list, and then clickCreate serverless network endpoint group.
Enter the following details:
Name: Enter
streamlit-app-neg.Region: Select
us-central1.Serverless network endpoint group type: SelectCloud Run.
Select service: Select the
gemini-streamlit-cloudrunCloud Run service.
ClickCreate.
ClickDone.
Clear theEnable Cloud CDN checkbox.
In thePolicy name box, enter
default-security-policy-gemini-app-backend.ClickCreate, and then clickOK.
ClickRouting rules to configure the routing rules.
Routing rules
ClickAdvanced host and path rule.
In theHost and path rules section, click(Default) Route traffic to backend "" for any unmatched hosts, and then enter the following details:
Action: SelectRoute traffic to a single backend.
Backend: Select
Note: This rule handles the traffic for any unmatched host.gemini-streamlit-app-backend.
ClickDone.
ClickAdd host and path rule to add a new rule.
UnderNew host and path rule, enter the following details:
Hosts: Enter the domain name used whilecreating the Google-managed certificate.
Path Matcher: Copy the following URL map configuration:
defaultService: projects/PROJECT_ID/global/backendServices/gemini-streamlit-app-backendname: matcher1routeRules: - matchRules: - prefixMatch: /gemini-streamlit-app priority:PRIORITY routeAction: weightedBackendServices: - backendService: projects/PROJECT_ID/global/backendServices/gemini-streamlit-app-backend weight: 100Replace the following:
PROJECT_ID: Your Google Cloud project ID.
PRIORITY: Specify the priority of the backend service bywhich the route rules are evaluated. In this scenario, set this to anyvalue because you created only one backend service.
ClickDone.
ClickReview and finalize to review the configuration and create the load balancer.
Review and finalize
Review the load balancer configuration.
To create the load balancer, clickCreate.
Add the IP address to the domain DNS records
Update the DNS records of your domain to point to the reserved IP address that wascreated for your load balancer. You might have to contact the administratorof your domain to complete this step.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.