Custom Domain for Web Apps on Cloud Run – How to Set Up Application Load Balancer on GCP

custom-domain-for-web-apps-on-cloud-run-–-how-to-set-up-application-load-balancer-on-gcp

This guide will walk through the steps of setting up a load balancer for Cloud Run instances in GCP. As well as the other features a load balancer offers, primarily our outcome will be a static outbound IP which we can then use in a DNS service of choice to configure a custom domain.

Some other articles of mine that may be of interest:

Let’s get started!

Prerequisities

  • You should already have a Cloud Run instance deployed

Creating a Load Balanacer

This will roughly follow the guide as per Set up a classic Application Load Balancer in the docs.

Step 1: Create a new load balancer, choosing the following:

  • Application Load Balanacer (HTTP/HTTPS)
  • Public facing (external)
  • Best for global workloads
  • Global external Application Load Balancer

Create Load Balancer

Step 2: Frontend Configuration
First, we need to reserve a static IP by clicking “Create IP address”

Create IP Address

Keep the IP version as IPv4, keep the port as 443 (important for Cloud run!), and be sure to choose an active certificate. We will keep the “additional certificates” as GCP default.

Step 2: Backend Configuration
When creating the backend configuration, set the backend type as “Serverless network endpoint group”. This then gives us the option to Add a backend and Create a new Serverless network endpoint group.

Create Backend Configuration

In Create Serverless network endpoint group, this is where you will select your Cloud Run instance which will receive all the traffic from the load balancer
Create Serverless Network Endpoint Group

If you intend to use your load balancer to disperse traffic over multiple backend services, this is where you can add these and later set routing rules to control which requests go to each.

In the meantime, we can leave everything else as the default options. Note that another thing you can do at this point is create a custom Cloud Armour policy for purposes such as IP whitelisting.

Step 3: Routing Rules
If you are only using the load balancer for a custom domain, then we can leave Routing rules as Simple host and path rule. If you set up multiple backend services in the previous step, this is where you can configure the routing for these.

Step 4: Review & Finalise
Finally, we review & finalise, and your options should look similar to mine in the image below:

Review & Finalise

Step 5: Public IP
Once the load balancer creation finished loading, you can then click on it’s details to reveal the public IP.

Public IP

Step 6: Custom Domain in DNS Provider
You can now use this IP in your DNS provider of choice to configure a custom domain.

And done!

Now all traffic to your custom domain will be received by the load balancer, and then routed accordingly as per the routing rules you set to your backend Cloud Run service(s)!

Application Load Balancer Cloud Run Diagram

Image source: Google Cloud

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
@classmethod-and-@staticmethod

@classmethod and @staticmethod

Next Post
ann:-omniauth-identity-v31.4

ANN: omniauth-identity v3.1.4

Related Posts