SBN

Creating CNAME for Google Cloud Run Service Functions

Creating CNAME for Google Cloud Run Service Functions

In this blog, we will create a CNAME for our cloudrun service function with path matchers. We will be using the load balancer method to create a CNAME. We will create three path matchers for three separate cloudrun services.

How to create a CNAME for Google cloud run service functions

  • Firstly we have to create a domain name in any domain registrar of your choice like Cloudflare. For example mysamplefunctions.com
  • To use this method we need a project owner or project editor role or the following permissions

Network Admin
Compute Instance Admin
Security Admin
Network Admin

Create load balancer and networking components

Compute Instance Admin

Create and modify NEGs

Security Admin

Create and modify SSL certificates

  • We need to set up a global IP address to reach the load balancer
    Run the following command

					
				

Console

Creating CNAME for Google Cloud Run Service Functions

  • Create a serverless NEG (network endpoint group) for your first cloudrun service let’s say. Image processor. The --cloud-run-serive should be the name that you see for the cloud run service in the cloud console

					
				

Console

Creating CNAME for Google Cloud Run Service Functions

Add the FQDN keep the other fields as is

Creating CNAME for Google Cloud Run Service Functions

  • Create a backend service for the same.

					
				

You cannot create global backend service from console. To create regional backend service

Creating CNAME for Google Cloud Run Service Functions

Specify the network enpoint group name created in the previous step in the below drop down menu.

Creating CNAME for Google Cloud Run Service Functions

  • Add the serverless NEG as a backend to backend service

					
				
  • Create a NEG for your second cloudrun service let’s say video processor.The --cloud-run-service should be the name that you see for the cloudrun service in the cloud console

					
				
  • Create backend service for same.

					
				
  • Add serverless NEG as backend to backend service.

					
				
  • Create a NEG for your third cloudrun service let’s say audio processor.The –cloud-run-service should be the name that you see for the cloudrun service in the cloud console

					
				
  • Create backend service for same.

					
				
  • Add serverless NEG as backend to backend service.

					
				
  • Create a URL map to route incoming requests to the backend service.

					
				

The --default-service will be used if no path is specified in the url.

  • Create path matchers for all the services.

					
				
  • Create a target HTTP(S) proxy to route requests to your URL map.

					
				

Console steps 13, 14, and 15:
a. Create a http load balancer

Creating CNAME for Google Cloud Run Service Functions

b. Create a URL map to route incoming requests to the backend service.

Creating CNAME for Google Cloud Run Service Functions

c. Create a URL map to route incoming requests to the backend service.

Creating CNAME for Google Cloud Run Service Functions

d. Click Create

  • Create a global forwarding rule to route incoming requests to the proxy.

					
				
  • After the load balancer is created, note the IP address that is associated with the load balancer: for example, 30.90.80.100. To point your domain to your load balancer, create an A record using your domain registration service.
  • Make sure that proxy is disabled in the domain registrar like Cloudflare so the traffic is routed to the load balancer.
  • So you can now access the functions in the following manner.
    – For image processor
    mysamplefucntions.com/image
    – For video processor.
    mysamplefucntions.com/video
    – For Audio processor.
    myaudioprocessor.com/audio
  • The document for reference are
  1. https://cloud.google.com/load-balancing/docs/https/setting-up-https-serverless#gcloud:-cloud-functions
  2. https://cloud.google.com/load-balancing/docs/url-map-concepts
  3. https://cloud.google.com/load-balancing/docs/negs/serverless-neg-concepts

*** This is a Security Bloggers Network syndicated blog from Cloudanix Blog authored by Cloudanix Author. Read the original post at: https://blog.cloudanix.com/cname-google-cloud-run-service-functions/