# Step 9: Deploy to Cloud Run and Cloud SQL, on your own domain

> Pagebee Academy, part 3 (Launch). Your app runs on Cloud Run, your data lives in a Cloud SQL Postgres database, and your domain points at both with HTTPS. Your agent does most of the typing.

Time: An afternoon. Cost: About $12 a month for the database; the app is usually free at launch.

## Why it matters

This is the step the app builders hide from you, and the reason they can charge what they like later. It's also less work than it sounds: three commands, which your agent will run.

**Cloud Run** builds your code into a container and runs it. When nobody's visiting, it scales to zero and costs nothing. Each month the first 2 million requests and a generous amount of compute are free, so a new product usually pays nothing for its app at all.

**Cloud SQL** is Postgres, managed by Google: backups, updates and a machine that doesn't go away. The smallest machine, `db-f1-micro`, costs about $12 a month. That will be your biggest bill for a while, and it's a fair one.

Your app and your database talk privately, and your passwords live in **Secret Manager**, never in the code.

## Do this

1. Pick one region for everything and stick to it. `europe-west1` (Belgium) or `us-central1` (Iowa) are both cheap and both support custom domains on Cloud Run.
2. Create the database. In the console, choose **SQL**, **Create instance**, **PostgreSQL**, and switch the edition to **Enterprise** (not Enterprise Plus, which is the default and costs far more). Or let your agent do it with this command:

```
gcloud sql instances create tally-db \
  --database-version=POSTGRES_18 --edition=enterprise \
  --tier=db-f1-micro --region=europe-west1 \
  --backup-start-time=02:00 --deletion-protection
```

3. Paste the prompt below. It creates the database user, stores the connection string in Secret Manager, and deploys.
4. The deploy it runs looks like this. `--max-instances 3` is your real spending cap: Cloud Run will never run more than three copies, however much traffic arrives.

```
gcloud run deploy tally --source . --region=europe-west1 \
  --allow-unauthenticated --max-instances=3 \
  --add-cloudsql-instances=PROJECT_ID:europe-west1:tally-db \
  --set-secrets=DATABASE_URL=database-url:1
```

5. Open the `run.app` address it prints and check the app works. Then prove you own the domain to Google (it opens Search Console; Cloudflare can add the record for you):

```
gcloud domains verify tally.app
```

6. Map your domain to the service, then ask Google which DNS records it wants:

```
gcloud beta run domain-mappings create --service=tally --domain=tally.app --region=europe-west1
gcloud beta run domain-mappings describe --domain=tally.app --region=europe-west1
```

7. Add those records in Cloudflare (your agent can, through the Cloudflare MCP) and set each one to **DNS only**, the grey cloud. Google issues the HTTPS certificate within about 15 minutes, sometimes up to a day.

## Paste into Claude Code

```text
Deploy this app to Google Cloud in europe-west1. The Cloud SQL instance tally-db exists. Create a database and a user with a strong generated password, store the full DATABASE_URL (using the /cloudsql unix socket) in Secret Manager as database-url, give the Cloud Run service account the Cloud SQL Client and Secret Manager Secret Accessor roles, and deploy with gcloud run deploy --source, --max-instances=3 and the secret mounted. Run the database migrations. Explain each command before you run it. Then write a short docs/deploy.md that records exactly how to deploy again, and commit it.
```

Once this works, ask your agent to make every push to `main` deploy automatically with a Cloud Build trigger. Then deploying is just pushing.

## The trap: Leaving the default database settings

The console's defaults pick Enterprise Plus and a bigger machine, which can cost well over $100 a month with nobody using it. Choose **Enterprise** and `db-f1-micro` to start, and turn on backups and deletion protection. You can make it bigger in a few clicks when you have the users to need it.

## Using something else

Fly.io, Railway and Render all run containers with a Postgres database next to them, with fewer steps. AWS (App Runner and RDS) is the same shape as this step. What matters is that your app is a container and your database is plain Postgres, so you can move either one.

## When to move off domain mapping

Cloud Run's domain mapping is still labelled Preview by Google. It's fine for launching and for a long while after. When you need the extra speed, or more than one service on one domain, Google's recommended route is a global load balancer in front of Cloud Run. Ask your agent to set one up when that day comes; your app doesn't change.

## Sources

- [Cloud Run: deploy from source](https://docs.cloud.google.com/run/docs/deploying-source-code)
- [Cloud Run: maximum instances](https://docs.cloud.google.com/run/docs/configuring/max-instances)
- [Cloud Run: map a custom domain](https://docs.cloud.google.com/run/docs/mapping-custom-domains)
- [Cloud Run pricing](https://cloud.google.com/run/pricing)
- [Cloud SQL: create an instance](https://docs.cloud.google.com/sql/docs/postgres/create-instance)
- [Cloud SQL: connect from Cloud Run](https://docs.cloud.google.com/sql/docs/postgres/connect-run)
- [Cloud SQL pricing](https://cloud.google.com/sql/pricing)
- [Cloud Run: secrets](https://docs.cloud.google.com/run/docs/configuring/services/secrets)

Checked 24 November 2026. https://pagebee.ai/academy/deploy
