Cloud Run lives outside your VPC
A VM has a network card in your subnet. It has an internal IP, it is part of the VPC, and chapters 1.1 to 7 apply to it directly. Cloud Run has none of that. It runs containers that Google starts and stops on demand, on Google's own infrastructure, outside your VPC.
By default, an outgoing call from Cloud Run goes straight to the internet from Google's serverless infrastructure. It never touches your VPC, routes, firewall or Cloud NAT. Two problems follow:
- Run by Google
- Your VPC
Wide by design - scroll it sideways.
| # | Problem | Why |
|---|---|---|
| 1 | It cannot reach private things | kade-db's 10.10.2.5 exists only inside kade-vpc, and Cloud Run is not in it |
| 2 | Its outgoing IP is unpredictable | Traffic leaves from a shared pool of Google addresses that changes all the time. There is nothing to put on PayGate's allow-list |
A real backend, one that talks to a private database and needs a fixed outgoing IP, must be connected to the VPC.
Two ways to connect to the VPC
- Run by Google
- Your VPC
- Allowed traffic and replies
Wide by design - scroll it sideways.
| # | Serverless VPC Access connector | Direct VPC egress | |
|---|---|---|---|
| 1 | How it works | A group of managed VMs that forward traffic from Cloud Run into your VPC | Each Cloud Run instance gets its own internal IP in a subnet you choose |
| 2 | Addresses used | A dedicated /28 for the connector VMs | About 2 per instance, from your subnet (below) |
| 3 | Cost | The connector VMs are billed all the time, used or not | No extra charge; network traffic only |
| 4 | Throughput | Limited by how many connector VMs you allow | Grows with the service |
| 5 | Latency | An extra hop | Lower |
| 6 | Something to run | Yes, the connector | No |
| 7 | Status | The original method | What Google now recommends |
35.199.224.0/19 from chapter 4. Once traffic is inside the VPC by either method, it follows your routes and your firewall rules like any other VPC traffic.Sizing the subnet for Direct VPC egress
This is the one planning step. Cloud Run takes addresses from the subnet in blocks of 16 (/28) so it can scale quickly, uses about 2 addresses per instance in steady state, and keeps a scaled-down revision's addresses for up to 20 minutes. During a deploy, the old and new revisions can both hold addresses:
Kadé: kade-api max 50 instances During a deploy: (50 old + 50 new) × 2 = 200 addresses sn-run 10.10.3.0/24 → 252 usable (chapter 2) → fits, with a small margin A /26 (60 usable) would run out during the first deploy under load.
- Addresses held in sn-run (dashed: the new revision)
Wide by design - scroll it sideways.
The addresses change all the time, so never write firewall rules for single Cloud Run IPs. Use the whole subnet range, the service's network tags, or its service account.
Egress: which traffic goes through the VPC
There are two layers of setting. First, is the service connected to the VPC at all? Second, if it is, which of its traffic uses that connection: private-ranges-only or all-traffic?
The drawing follows the same two calls, one to the database and one to PayGate, under each setting:
- Run by Google
- Your VPC
- Allowed traffic and replies
Wide by design - scroll it sideways.
| # | Setting | Through the VPC | Fits |
|---|---|---|---|
| 1 | Not connected | Nothing | A service with nothing private to reach |
| 2 | private-ranges-only | Only traffic to private ranges (RFC 1918, plus the Private Google Access addresses) | A private database, and nothing that checks the caller's IP |
| 3 | all-traffic | Everything, so internet calls leave through Cloud NAT | Anything that allow-lists your outgoing address, like PayGate |
Two things to add when you choose all-traffic:
| # | Need | Why |
|---|---|---|
| 1 | Cloud NAT must cover sn-run | Otherwise internet calls enter the VPC and find no way out. Add sn-run to kade-nat (chapter 7 section 03) |
| 2 | Google APIs still work | Calls to Google APIs now go through the VPC too. Private Google Access handles them, and Cloud NAT turns it on for sn-run automatically (chapter 7 section 02) |
Firewall rules for Cloud Run traffic
Once kade-api's traffic enters kade-vpc from sn-run, kade-db's ingress rules judge it like any other packet (chapter 5.1). The rule kade-api-to-db allowed traffic from VMs running as sa-kade-api. Cloud Run is not a VM, so give it a rule of its own:
Ingress: who may reach the service
Ingress is a completely separate setting. It controls who may reach the service, whatever the egress settings are.
| # | Ingress value | Reachable from | Blocked |
|---|---|---|---|
| 1 | all | Anyone on the internet, directly at the run.app address | Nothing |
| 2 | internal | Your VPC, plus a few Google services such as Pub/Sub and Eventarc | The run.app address from the internet |
| 3 | internal-and-cloud-load-balancing | Your VPC, plus a load balancer in front | Direct internet access to run.app |
- Run by Google
- Allowed traffic and replies
- Firewall and access rules
Wide by design - scroll it sideways.
The ingress setting is one of three checks a request has to pass, in this order:
- Run by Google
- Allowed traffic and replies
- Firewall and access rules
Wide by design - scroll it sideways.
| # | Layer | Question it answers | Set with |
|---|---|---|---|
| 1 | Ingress setting | Can this network path reach the service at all? | --ingress |
| 2 | IAM invoker check | Is this caller allowed to invoke it? | roles/run.invoker, or --allow-unauthenticated for public services |
| 3 | Default URL | Does the run.app address exist at all? | --no-default-url removes it |
One service calling another
Kadé has one service today. Suppose a second one appears: kade-notify, which sends order emails and should never be reachable from the internet, so its ingress is internal. kade-api now has to call it, and two things must both be true:
- Run by Google
- Your VPC
- Allowed traffic and replies
- Firewall and access rules
Wide by design - scroll it sideways.
| # | Check | What makes it pass |
|---|---|---|
| 1 | The call arrives as internal | It must travel through the VPC. all-traffic egress does this, with Private Google Access on the subnet. A call from a service that is not connected, or uses private-ranges-only with no extra DNS setup, goes around the VPC and gets a 404 |
| 2 | The caller is allowed | kade-api's service account has roles/run.invoker on kade-notify, and each request carries an identity token for it. No --allow-unauthenticated on an internal service |
Scaling multiplies everything
A VM is one machine with one address. A Cloud Run service is as many copies as the load needs, and each copy brings its own connections, ports and addresses:
- Run by Google
- Your VPC
Wide by design - scroll it sideways.
| # | Guard | Why |
|---|---|---|
| 1 | Set --max-instances | It caps all three at once. Kadé uses 50 |
| 2 | Keep the pool per instance small | Max instances × pool size must stay under the database's connection limit, or a traffic spike locks everyone out of the database |
| 3 | Reuse outgoing connections | Every instance draws on kade-nat's ports when it calls PayGate (chapter 7 section 05) |
What else is different from a VM
| # | Topic | On Cloud Run |
|---|---|---|
| 1 | Its addresses in sn-run | For outgoing traffic only. Nothing can connect to an instance's 10.10.3.x address; requests always come in through Google's front end |
| 2 | A fixed address to come in on | There is none. The load balancer provides it (chapter 11) |
| 3 | HTTPS | Google's front end handles TLS and passes plain HTTP to the container's port (8080 by default) |
| 4 | Private DNS | Once connected to kade-vpc, the service resolves the VPC's private zones, so db.kade.internal works (chapter 8) |
| 5 | Limiting what it may call | Its traffic in the VPC obeys egress firewall rules too. Give the service a network tag and write rules for it (chapter 5.1) |
| 6 | Jobs and functions | Cloud Run jobs and Cloud Run functions take the same VPC and egress settings |
Quick reference
Read any Cloud Run service's networking as two separate questions:
| # | Direction | Question | Options |
|---|---|---|---|
| 1 | Ingress | The door in: who can reach it? | all · internal · internal-and-cloud-load-balancing |
| 2 | Egress | The door out: what can it reach, and from which IP? | Not connected, or connected with private-ranges-only or all-traffic |
| # | Ingress | Egress | Reaches private IPs | Internet egress IP | Fits |
|---|---|---|---|---|---|
| 1 | all | none | ✗ | Random Google pool | Public API with nothing private, and no load balancer protection |
| 2 | all | private-ranges-only | ✓ | Random Google pool | Public service with a private database; nothing allow-lists it |
| 3 | internal-and-cloud-load-balancing | all-traffic | ✓ | Fixed NAT IP | The hardened production shape: behind a load balancer and WAF, private database, allow-listable egress. Kadé's choice |
| 4 | internal | all-traffic | ✓ | Fixed NAT IP | An internal-only service calling an allow-listed partner API |
Try it: what can reach kade-api, and what can it reach?
3 of 6 paths are not what Kadé needs.
| Path | What happens | |
|---|---|---|
| ingress | Shopper through the load balancer | Reaches kade-api through the load balancer and Cloud Armor |
| ingress | Anyone at the run.app address | Reaches kade-api directly, skipping the load balancer and Cloud Armor (the trap) |
| ingress | kade-worker, from inside kade-vpc | Reaches kade-api: counts as internal under every setting |
| egress | kade-api → kade-db 10.10.2.5:5432 | Fails: kade-api is not in the VPC, and 10.10.2.5 exists only there |
| egress | kade-api → PayGate (allows only 34.87.200.7) | Leaves from a random Google IP; PayGate refuses it |
| egress | kade-api → Cloud Storage API | Directly from Google's serverless network |
Back to Kadé
Commands in this chapter
Commands 1 and 2 are read-only. Commands 3 to 5 change the project.
See a service's ingress and egress settings
- What it shows: The ingress value and the VPC settings of kade-api's current revision.
- What to look for: The
run.googleapis.com/ingressannotation, andrun.googleapis.com/network-interfacesandvpc-access-egressin the revision template.
gcloud run services describe kade-api --region=asia-southeast1 --format=yaml \ | grep -E "ingress|network-interfaces|vpc-access-egress"Find every service with ingress "all"
- What it shows: Each Cloud Run service in the region with its ingress setting.
- What to look for:
allon anything that has a load balancer in front of it (the trap in section 05).
gcloud run services list --region=asia-southeast1 \ --format="table(metadata.name,metadata.annotations['run.googleapis.com/ingress'])"Create the Cloud Run subnet and add it to the NAT (changes the project)
- What it shows: Step 1: sn-run exists and Cloud NAT covers it.
- What to look for: The NAT's subnet list now includes sn-run. The
--nat-custom-subnet-ip-rangesflag replaces the list, so name all three.
gcloud compute networks subnets create sn-run \ --network=kade-vpc --region=asia-southeast1 --range=10.10.3.0/24gcloud compute routers nats update kade-nat \ --router=kade-router --region=asia-southeast1 \ --nat-custom-subnet-ip-ranges=sn-app,sn-data,sn-runDeploy with Direct VPC egress and locked ingress (changes the project)
- What it shows: Step 3: all outgoing traffic through kade-vpc, reachable only from the VPC and the load balancer.
- What to look for: Command 1 shows both settings. Replace the image path with your own.
gcloud run deploy kade-api --region=asia-southeast1 \ --image=asia-southeast1-docker.pkg.dev/kade-prod/kade/api:latest \ --network=kade-vpc --subnet=sn-run --vpc-egress=all-traffic \ --ingress=internal-and-cloud-load-balancing \ --allow-unauthenticated --max-instances=50Close the run.app bypass on an existing service (changes the project)
- What it shows: The one-line fix for the trap in section 05.
- What to look for: The
run.appaddress returns 404 from outside, while the site still works through the load balancer. Set up the load balancer first, or the service becomes unreachable.
gcloud run services update kade-api --region=asia-southeast1 \ --ingress=internal-and-cloud-load-balancing