How to connect your Google load balancing with Google Cloud run

Chaiwat Tungtongsoontorn
Tri Petch Digital
Published in
5 min readMar 20, 2024

Introduction

You might need to create some simple websites or API services via GCP. And then you need to map these backend service with Google Load Balancing because you might have many microservices to connect many applications.

In this blog, I will show how to connect your Google cloud running service from step by step.

Contents

  • How to config your google cloud run service to connect with your Google Load Balancing.
  • How to create Load Balancing and connect to your Google Cloud Run
  • Map you Load Balancer with your registered domain

How to config your Google Cloud Run service
First thing first, you need to go to your google cloud run dashboard. Then you start simple service by click create service menu.

  • On “Deploy one revision from an existing container image” section, select your container image that you have put to your images registry. For this blog, I will demonstrate how to connect, so I select Google sample Container by clicking on TEST WITH A SAMPLE CONTAINER phrase.
  • Next step is to fill you you service name and select your region. (please aware of unmapped domain regions)
  • On CPU allocation and pricing, I will pick “CPU is only allocated during request processing” option according to this demo, I do not need to spend too much cost.
  • Set Autoscaling with min number of instances with 1 and maximum with 1 (depends on your size of your application).
  • For ingress go for “Allow internal traffic and traffic from Cloud Load Balancing” option.
  • For *Authentication, select “Allow unauthenticated invocations” option.
  • Rest of configurations leave them as default.

All you configuration should be like this.

google cloud run configuration

Congratulation🎉🎉! You now have Google Cloud Run service but you cannot access it because we set ingress as Allow internal traffic and traffic from Cloud Load Balancing. Let move to the next path create Load Balancer.

How to create Load Balancing and connect to your Google Cloud Run

  • Expand google navigators and select Networking services -> Load Balancing.
  • Click “CREATE LOAD BALANCER” menu.
  • Select “HTTP(S) Load Balancing”
  • Click continue
  • Fill you load balancer name
  • On the Left panel, select “Backend configuration” then click dropdown and click “CREATE A BACKEND SERVICE” label again
  • Now your backend service need to connect to serverless network endpoint group. These network contains your serverless such as your google cloud run applications. Hence we are going to create NEG then click dropdown and click CREATE “SERVERLESS NETWORK ENDPOINT GROUP”. Your NEG should be type as Cloud Run. Please select your region where you google cloud run stands.
  • Leave the rest of backend service as default
  • In “Host and path rules”, set to mode Simple host and path rule.
  • Before we go to frontend menu, we will create static ip by go to VPC network -> External IP addresses then click label “RESERVE STATIC ADDRESS” (Please aware of orphan IP would be charge with higher rate). You IP type should be Global. We will use it for next step.
  • For the frontend section, you can now specify IP and Port, but IP must not be ephemeral. Your domain name needs static ip to map your domain. Now we going to create HTTP go for port 80 and select IP which we created on previous step.
  • for HTTPs go for port 443. for Certificate we are about to create the new one with type Google-managed certificate. And select IP which we created on previous step.

Your frontend configuration should be looked like figure below.

  • Review and finalize.
  • Click “CREATE”

Yeah!! WE just created Google Load Balancing. Now you can access you cloud run with your ip which you create. Or you can find your ip on Load Balancer’s dashboard then click on your load balance’s name. Now we meet the final part.

Map you Load Balancer with your registered domain

You should firstly own your domain with domain registration. You might have panel from your Provider. Then go to your “DNS records” section. You are going to alias your ip with your domain name with type “A” record as figure below.

*This process might take from 2–48 hours for mapping your domain name.

🎉🎉🎉🎉🎉🎉 Congratulations🎉🎉🎉🎉🎉🎉
Now you website or you API service can be now connected with your DNS and has Load Balancer for proxy server. And of course Our website, that run on Google Cloud Run, has SSL certificate.

If you have any question, please let me know. I appreciate for your any comments.

For those who interest joining us team in Tri Petch IT Solutions
Link — https://career.tripetchgroup.com/job-opening?bu_id=4

Contact us or find more Blogs here.
- https://medium.com/tri-petch-digital

--

--