First question: connect them at all?
Builds on6. Two networks
Two VPCs are two separate worlds (chapter 2 section 01). The honest default for staging is to leave it that way: a separate project with its own VPC, its own small database, and its own Cloud NAT, connected to nothing. It cannot break production, and production data cannot leak into it.
- Your VPC
- Allowed traffic and replies
Separate and unconnected: the simplest and safest shape. The only shared things are the folder's hierarchical firewall policy and organization policies (chapters 5.2 and 17), which apply to both projects automatically.
Wide by design - scroll it sideways.
| # | Connect them when… | Keep them apart when… |
|---|---|---|
| 1 | Something in one VPC must call a private IP in the other (a shared internal service, a shared database) | Each environment has its own copy of everything it needs. Kadé's case |
| 2 | One team must run the network for many projects (central firewall, central IP plan) | There is one person running the network anyway |
| 3 | Several projects must share one VPN or Interconnect to the office | Staging does not need the office network |
10.20.0.0/16). Then connecting them later stays possible.Three ways to connect
If two networks do need to talk, GCP gives three shapes. They solve different problems:
| # | VPC peering | Shared VPC | Private Service Connect | |
|---|---|---|---|---|
| 1 | The shape | Two separate VPCs, joined so they can route to each other | One VPC, owned by a host project, used by several service projects | One endpoint IP in your VPC that reaches one service in another |
| 2 | What is connected | Every subnet on both sides | Nothing needs connecting: it is a single network | Only that one service |
| 3 | Who runs the network | Each side runs its own (firewall, routes) | The host project's network team, for everyone | Each side runs its own |
| 4 | Ranges may overlap? | no | Not applicable: one plan | yes |
| 5 | Needs an organization? | No; works across projects and organizations | Yes | No |
| 6 | Typical use | Two teams' VPCs that need some private traffic | A company where one platform team owns networking | Reaching one shared service, or a vendor's service (chapter 9) |
VPC peering, and its two rules
Peering joins two VPCs at the routing level. Each side must create its half of the peering; when both halves exist, each VPC learns the other's subnet routes (chapter 4) and traffic flows on internal IPs, over Google's network, with no gateway or VPN. A few things are not shared, and they surprise people:
| # | Not shared by peering | So you must… | Chapter |
|---|---|---|---|
| 1 | Firewall rules | Allow the other VPC's range in each VPC's own rules | 5.1 |
| 2 | Custom routes (static, dynamic from a VPN) | Turn on export on one side and import on the other | 4, 9 |
| 3 | DNS: private zones and VM names | Add a peering zone (DNS peering) | 8 |
| 4 | Anything the other VPC itself reaches through a peering | Nothing helps: rule 2 below | 9 |
Two rules decide whether peering works at all. Each tab shows one:
What each side learns, and what it does not
- subnet routes10.20.1.0/24, 10.20.3.0/24 appear in kade-vpc (and the reverse)
- firewall ruleseach VPC still needs a rule allowing the other's range
- DNSprivate zones and VM names stay local unless a peering zone is added
- custom routesonly with export on one side and import on the other
Both projects create their half of the peering. Once both exist, each VPC learns the other's subnet routes, so 10.10.1.20 can reach 10.20.1.10 directly over Google's network. Each side still needs a firewall rule allowing the other's range, and DNS names are not shared unless you add a peering zone.
Show as config
kade-vpc: peering prod-to-staging → kade-staging/staging-vpc staging-vpc: peering staging-to-prod → kade-prod/kade-vpc both halves exist → ACTIVE → subnet routes exchanged
Shared VPC
Shared VPC turns the question around: instead of joining two networks, many projects use one network. A host project owns the VPC, its subnets, routes and firewall rules. Service projects attach to it and create their VMs and Cloud Run services directly in its subnets. Each team keeps its own project for billing and permissions; the network is run in one place.
An example layout, not Kadé's: Kadé keeps two separate projects (section 07).
| # | Piece | Who | What it allows |
|---|---|---|---|
| 1 | Shared VPC Admin (roles/compute.xpnAdmin) | Granted on the organization or folder | Makes a project a host, and attaches service projects |
| 2 | Network User (roles/compute.networkUser) | Granted on the host project, or on single subnets | Lets a service project's people create resources in those subnets, and nowhere else |
| 3 | Network Admin, Security Admin | The platform team, in the host project | Change subnets, routes, firewall rules for everyone |
Private Service Connect, the narrow option
When the only thing one network needs from another is a single service, there is no reason to join the whole networks. A Private Service Connect endpoint (chapter 9 section 04) gives the consumer one internal IP that forwards to that service. Nothing else is reachable, the ranges may overlap, and there is no transitivity problem. Chapter 9's tab "Cloud SQL from many VPCs" is exactly this pattern for a shared database.
What to learn next, if you need the full picture
This chapter is enough to read the rest of the course and to answer exam questions. To design, build and run a real multi-VPC network, these are the additional topics to learn, roughly in order:
| # | Topic | Why you would need it |
|---|---|---|
| 1 | IP address planning across many networks | Every network you may ever connect must have its own non-overlapping block, decided up front (chapter 0's plan, at company scale) |
| 2 | Shared VPC design and IAM | Host and service projects, subnet-level permissions, who owns firewall rules, how Cloud Run and GKE attach to shared subnets |
| 3 | VPC peering details | Custom route export and import, peering limits and quotas, how firewall rules and DNS work across a peering |
| 4 | Network Connectivity Center (NCC) | Google's hub-and-spoke service. With VPC spokes it connects many VPCs transitively, which plain peering cannot |
| 5 | Cross-project DNS | DNS peering zones and cross-project zone binding, so names resolve everywhere they should (chapter 8) |
| 6 | Private NAT | Connecting networks whose ranges already overlap and cannot be renumbered (chapter 7 section 08) |
| 7 | Hybrid connectivity at scale | Sharing one VPN or Interconnect across many VPCs (chapter 15 is the single-VPC version) |
| 8 | Governance across projects | Hierarchical firewall policies, organization policies that restrict which subnets and projects can be used, VPC Service Controls (chapters 5.2 and 17) |
Back to Kadé
Commands in this chapter
Commands 1 to 4 are read-only. Command 5 changes the project and is shown for reference; Kadé does not run it.
List a network's peerings
- What it shows: Every peering on kade-vpc, its state, and its route export and import settings.
- What to look for:
servicenetworking-googleapis-com(chapter 9) is a peering too.INACTIVEmeans the other side has not created its half.
gcloud compute networks peerings list --network=kade-vpcSee the routes a peering shares
- What it shows: Routes kade-vpc receives from, or sends to, one peering.
- What to look for: The other side's subnet ranges in the incoming list. A missing range usually means an overlap or an export setting.
gcloud compute networks peerings list-routes servicenetworking-googleapis-com \ --network=kade-vpc --region=asia-southeast1 --direction=INCOMINGIs this project in a Shared VPC?
- What it shows: The host project this project is attached to, if any.
- What to look for: Empty output for Kadé: kade-prod is a standalone project.
gcloud compute shared-vpc get-host-project kade-prodList service projects of a host
- What it shows: In a Shared VPC, every project attached to a host project.
- What to look for: Only the projects you expect. Replace the host project ID with your own.
gcloud compute shared-vpc associated-projects list HOST_PROJECT_IDCreate one half of a peering (changes the project; reference only)
- What it shows: How a peering starts. The other project runs the same command pointing back.
- What to look for: State
INACTIVEuntil both halves exist, thenACTIVE. It fails immediately if any subnet ranges overlap.
gcloud compute networks peerings create prod-to-staging \ --network=kade-vpc --peer-project=kade-staging --peer-network=staging-vpc