If you're hosting your website on Google Cloud Run, you might want to use your own domain name instead of the default URL Google gives you. It's not hard to set up, and it makes your site look more professional. In this post, I'll walk you through how to add a custom domain to your Cloud Run service, keeping it simple and cheap.
Prerequisite: I'm assuming you've already set up your Cloud Run service in a Google Cloud Platform project. If you haven't, check out my earlier article on setting up Cloud Run.
Before Google lets you use your domain with Cloud Run, you need to prove you own it. This happens through Google Search Console. Here's what to do:
Note: You'll need access to your registrar's DNS management page. If you're stuck, their help docs should point you in the right direction.
Once your domain is verified, you can connect it to Cloud Run. Here's how:
What's this A and AAAA stuff? A records connect your domain to IPv4 addresses, and AAAA records do the same for IPv6. Cloud Run uses multiple addresses for reliability, so you get four of each.
Tip: After adding the records, you can check if they're working with a tool like "dig" or an online DNS checker.
Want your site to work with www.yourdomain.com too? It's an extra step, but easy.
In Cloud Run, add another mapping, this time for www.yourdomain.com.
Google will give you a CNAME record instead of A or AAAA records.
Add that CNAME record to your registrar's DNS settings.
Finish the mapping in Cloud Run.
What's a CNAME? It's like a shortcut - it points www.yourdomain.com to your main Cloud Run address.
After setting up the DNS records, Google handles the security part by creating an SSL/TLS certificate. This makes your site use HTTPS, which is a must these days. It takes about 30 minutes, though sometimes a bit longer. You'll see the status update in Cloud Run when it's done. While it's processing, your site might not load, or you might see browser warnings. That's normal - just wait it out.
Here is how your mappings will appear after you have correctly followed the steps above:
Here's the breakdown:
Domain: About $10-15 per year, depending on your registrar and domain type.
Cloud Run: There's a free tier that covers a decent amount of usage. After that, you pay only for what you use-requests, CPU, and memory. For small sites, it's often pennies a month.
The domain mapping itself? Free. No hidden fees there.
DNS Delays: Propagation can take up to 48 hours, but it's usually faster.
Typos: Mess up a DNS record, and your site won't work. Double-check them.
Subdomains: If you're mapping something like blog.yourdomain.com, make sure you set it up right.
SSL Issues: If HTTPS doesn't kick in, peek at Cloud Run's docs or ask for help online.
That's it! Once everything's set, your website will run on your custom domain with HTTPS, all hosted on Cloud Run. It's a cheap way to get a professional setup - just the cost of your domain and whatever Cloud Run usage you rack up beyond the free tier.
Enjoyed this blog post? Check out these related posts!
Optimizing Reflex Performance on Google Cloud Run
A Comparison of Gunicorn, Uvicorn, and Granian for Running Reflex Apps
Read More..
Adding middleware to FastAPI Applications: Process Time, Security, and Compression
A practical guide to implementing middleware in FastAPI for better performance, security, and efficiency.
Read More..
Deploying Reflex Front-End with Caddy in Docker
A step-by-step guide to building and serving Reflex static front-end files using Caddy in a Docker container
Read More..
Simple CI/CD for Your FastAPI App with Google Cloud Build and Cloud Run
Push code, deploy automatically: A simple CI/CD guide for your web app.
Read More..
Have a project in mind? Send me an email at hello@davidmuraya.com and let's bring your ideas to life. I am always available for exciting discussions.