DEV Community

Rubens Zimbres
Rubens Zimbres

Posted on • Originally published at Medium on

Boost Your Website’s Performance with Cloud Run Autoscaling


Domain Mapping with Cloud Run

Last, year, during a meeting in Mountain View with a fellow developer, he said to me that my lecture about Cloud Run in Google Cloud helped him solve a big problem he had in the website of his company. The website didn’t scale properly according to a higher demand, and either he spent too much money with a big infrastructure, or the website was not able to handle traffic in peak hours, making him lose money.

So, I decided to test it myself. Initially I thought I wouldn’t be able to put a website in production from beginning to end, because at first I didn’t understand some issues in domains, like DNS setup, and I also didn’t have a clue on how to use my Cloud Run instance to host the website.

Fortunately, Google Gemini helped me to connect my Cloud Run service to my custom domain from GoDaddy. First, I got the domain at GoDaddy plus the email client (Microsoft 365, only option) for 36.87 USD a year. Then, I did the basic setup, like placeholder page, email config, etc. Simple job.

Then, I went to the Google console / Cloud Run / Domain mappings. I didn’t find the path in the console, but the documentation has it:

Mapping custom domains | Cloud Run Documentation | Google Cloud

This link will lead you to the domain mapping page. There, you click Add Mapping and select the Cloud Run service you want to attach. In my case, it was a Flask application.

Then you will add a mapping, selecting the domain you have (mydomain.com), then add www to the subdomain field below.

This task will take around 20 minutes to 3 hours to complete.

Meanwhile, in this same page, click the three buttons on the right (DNS Register) and copy the data:

ghs.googlehosted.com.

Now, go to GoDaddy / Domain Settings / DNS Management:

Here, you will add some Google records, one by one:

  • Type: A
  • Host/Name: @
  • 216.239.32.21 216.239.34.21 216.239.36.21 216.239.38.21
  • TTL: 3600 (or 1 hour)

And one more, the DNS record you got from Cloud Run Mapping:

  • Name: www
  • Type: CNAME
  • Data: ghs.googlehosted.com.
  • TTL: 3600 (or 1 hour)

Then, you can access https://dnschecker.org/ to check for DNS propagation.

Here, some hints about what I said so far:

  • The A records are Google’s global IP addresses that handle the routing to your Cloud Run service
  • Don’t use the A records I listed above without verifying them in your Cloud Console — Google might give you different IPs
  • Always copy the IPs directly from Google Cloud Console to avoid any mistakes

In DNS (Domain Name System), Type A records, CNAME records, and the @ symbol serve specific purposes:

Type A Records (Address record) map a domain name to an IPv4 address. They are used when you want to point a domain or subdomain directly to an IP address. AAAA records map to IPv6.

CNAME Records (Canonical Name records) map one domain name to another domain name. They allow you to create aliases for domains and simplifies DNS management. This is what we want here. The idea is to redirect one domain to another domain (e.g., ‘www’ to the main domain, or subdomains pointing to external services like CDN, cloud platforms, or email services). In our case, map https://my-app-135478965.us-central1.run.app from Cloud Run to our domain www.mydomain.com

The basic difference between a CNAME and a A Record is that, unlike an A record, a CNAME cannot point to an IP address; it can only points to another domain name.

The @ in DNS Records is a placeholder in DNS records that represents the root domain or the domain name itself.

Now, after 20 minutes to 3 hours, the domain mapping will be successful:

At this moment, your GoDaddy website will be running in the Cloud Run app. Now you must verify Domain Ownership at GoDaddy:

  • Google will provide a TXT record that you need to add in GoDaddy’s DNS management
  • Wait for verification (can take 24–48 hours)

First, get the verification code from Search Console / Users / Three dots / Details of Propery Ownership. It usually looks something like this : google-site-verification=xxxxxxxxxxxxx

Then, paste in GoDaddy’s Verify Ownership, inside DNS Records and add the meta tag to your website.

Once verified, Google Cloud will provision an SSL certificate automatically. Wait for the SSL certificate to be provisioned (can take up to 24 hours) and test your domain by visiting it in a browser.

Now, you can use the following setups to scale your website:

  • min-instances and max-instances : this is how much your website will scale. In Cloud Run, instances can scale to zero, what can generate big savings.
  • concurrency: this limits how many requests a container instance handles simultaneously (default is 80)
  • Traffic Splitting : Traffic is split between versions by percentage, so that you can do an A/B test. Traffic splitting is ideal for A/B testing new features, gradual rollouts, testing performance between versions and comparing user behavior.

When using Cloud Run with a custom domain, you don’t need to manually manage SSL certificates at all, Google Cloud handles this automatically for you. Once you set up the domain mapping and verify ownership:

  • Google Cloud automatically provisions a free SSL certificate
  • The certificate is managed and renewed automatically by Google
  • You don’t need to do anything on the Cloud Run side
  • You don’t need to purchase or install any certificate yourself

This whole process of domain mapping costs ZERO dollars. You only pay for the Cloud Run instance running. By the way, DO NOT scale your Cloud Run instance to zero during this process. Also, you don’t need to purchase an SSL certificate from GoDaddy.

Once everything is set up, your users will see the padlock icon (🔒) in their browser, indicating a secure HTTPS connection, and all traffic will be encrypted automatically.

Acknowledgements

✨ _Google ML Developer Programs and Google Cloud Champion Innovators Program supported this work by providing Google Cloud Credits _✨

🔗 https://developers.google.com/machine-learning

🔗 https://cloud.google.com/innovators/champions?hl=en

Top comments (0)