In this step, you create an Application Load Balancer to distribute the traffic to backend instances hosted on Cloud Run. In the load balancer configuration, you define the routing rules, which determine how the load balancer directs the traffic. Routing rules include host rules and path matches, which constitute the configuration components of an external Application Load Balancer's URL map.
Note that to complete this step, you must have a valid domain name or a valid self-managed certificate.
Create a load balancer for the Cloud Run service
In the Google Cloud console, go to the Load balancing page.
Click Create load balancer.
In the Type of load balancer section, click Application Load Balancer (HTTP/HTTPS), and then click Next.
In the Public facing or internal section, click Public facing (external), and then click Next.
In the Global or single region deployment section, click Best for global workloads, and then click Next.
In the Load balancer generation section, click Global external Application Load Balancer, and then click Next.
Click Configure.
In the Load Balancer name field, enter
gemini-streamlit-app-lb
.Configure the load balancer by completing the Frontend configuration, Backend configuration, and Routing rules sections.
Frontend Configuration
Specify the following Frontend configuration:
Name: Enter
gemini-streamlit-app-frontend
.Protocol: Select HTTPS (includes HTTP/2 and HTTP/3).
Network Service Tier: Set the IP address by reserving a new external static IP address. While reserving the new IP address, specify
genai-app-ip
as the Name.Certificate: Perform the following steps to create a new Google-managed certificate:
Click Create a new certificate.
Specify the following details:
Name: Enter
my-genai-app-certificate
.Create mode: Click Create Google-managed certificate.
Domains: Enter the domain name for provisioning the certificate.
Click Create.
For more information about Google-managed SSL certificates, see Use Google-managed SSL certificates.
- Select the Enable HTTP to HTTPS redirect checkbox.
Click Done.
Click Backend configuration to configure the backend.
Backend configuration
Click the Backend services & backend buckets list and then click CEnter the following details:
Name: Enter
gemini-streamlit-app-backend
.Backend type: Click Serverless network endpoint group.
Backends: On the New Backend card, perform the following steps:
Click the Serverless network endpoint groups list, and then click Create serverless network endpoint group.
Enter the following details:
Name: Enter
streamlit-app-neg
.Region: Select
us-central1
.Serverless network endpoint group type: Select Cloud Run.
Select service: Select the
gemini-streamlit-cloudrun
Cloud Run service.
Click Create.
Click Done.
Clear the Enable Cloud CDN checkbox.
In the Policy name box, enter
default-security-policy-gemini-app-backend
.Click Create, and then click OK.
Click Routing rules to configure the routing rules.
Routing rules
Click Advanced host and path rule.
In the Host and path rules section, click (Default) Route traffic to backend "" for any unmatched hosts, and then enter the following details:
Action: Select Route traffic to a single backend.
Backend: Select
gemini-streamlit-app-backend
.
Click Done.
Click Add host and path rule to add a new rule.
Under New host and path rule, enter the following details:
Hosts: Enter the domain name used while creating the Google-managed certificate.
Path Matcher: Copy the following URL map configuration:
defaultService: projects/PROJECT_ID/global/backendServices/gemini-streamlit-app-backend name: matcher1 routeRules: - matchRules: - prefixMatch: /gemini-streamlit-app priority: PRIORITY routeAction: weightedBackendServices: - backendService: projects/PROJECT_ID/global/backendServices/gemini-streamlit-app-backend weight: 100
Replace the following:
PROJECT_ID: Your Google Cloud project ID.
PRIORITY: Specify the priority of the backend service by which the route rules are evaluated. In this scenario, set this to any value because you created only one backend service.
Click Done.
Click Review and finalize to review the configuration and create the load balancer.
Review and finalize
Review the load balancer configuration.
To create the load balancer, click Create.
Add the IP address to the domain DNS records
Update the DNS records of your domain to point to the reserved IP address that was created for your load balancer. You might have to contact the administrator of your domain to complete this step.