GCP Networking — VPC Network Peering & Shared VPC
- Get link
- X
- Other Apps
GCP Networking — VPC Network Peering & Shared VPC
1. VPC Network Peering — Why?
Imagine two separate VPC networks:
VPC-A VPC-B VM1 ──────────────── VM2 Private connection
Normally, if they are isolated, you might use:
- External IP addresses
- VPN
- Other connectivity solutions
But VPC Network Peering allows two VPC networks to communicate privately using internal IP addresses.
Simple definition
VPC Network Peering = Private connectivity between two separate VPC networks.
The two VPCs can be:
- In the same project
- In different projects
- Even under different organizations
2. Real-world example
Suppose:
Consumer Organization | Consumer VPC | VM-A
and
Producer Organization | Producer VPC | VM-B
The consumer needs to access a service running in the producer's VPC.
Instead of:
Consumer → Internet → Producer
you can use:
Consumer VPC ─── VPC Peering ─── Producer VPC VM-A VM-B
Traffic can use private/internal IP addresses.
3. Two-sided configuration is required
This is very important.
Peering is not established by only one VPC.
Both administrators must configure peering.
Consumer Admin | | peer Consumer → Producer ↓ Consumer VPC ←──────→ Producer VPC ↑ | Producer Admin | | peer Producer → Consumer
Once both configurations match:
Peering State = ACTIVE
Then Google Cloud exchanges subnet routes.
Before both sides configure:
Peering = INACTIVE
After both sides configure:
Peering = ACTIVE Routes exchanged Private communication possible
4. Who controls the VPC after peering?
This is one of the most important concepts.
VPC Network Peering does NOT combine the two VPCs into one VPC.
They remain administratively separate.
For example:
VPC-A VPC-B Admin A Admin B Firewall A Firewall B Routes A Routes B VPN A VPN B Network settings A Network settings B
So:
Peering gives connectivity, not centralized management.
Each administrator continues managing their own VPC.
5. Firewall rules still matter
Suppose:
VM-A (VPC-A) ↓ VPC Peering ↓ VM-B (VPC-B)
Even though the networks are peered, firewall rules still determine whether traffic is allowed.
Think:
Peering = Can the networks connect? Firewall = Is this particular traffic allowed?
Both are important.
6. VPC Peering is distributed/decentralized
VPC Network Peering is useful when different teams or organizations need to maintain control over their own networks.
Example:
Company A VPC-A | | Peering | VPC-B Company B
Company A doesn't suddenly get control over Company B's:
- Firewall rules
- Routes
- VPN
- Network administration
Each side remains independent.
7. Supported Google Cloud services
VPC Network Peering works with services such as:
- Compute Engine
- Google Kubernetes Engine (GKE)
- App Engine flexible environment
8. Network Administrator permission
You need appropriate network administration permissions/role to configure VPC Network Peering.
So normally:
Network Administrator ↓ Configure peering
9. CIDR ranges cannot overlap
This is a very important exam/lab concept.
Suppose:
VPC-A Subnet: 10.10.0.0/24
and:
VPC-B Subnet: 10.10.0.0/24
❌ They cannot be peered because the CIDR ranges overlap.
You need something like:
VPC-A 10.10.0.0/24 VPC-B 10.20.0.0/24
✅ No overlap → can be peered.
Why?
Google Cloud needs to know exactly where to send traffic.
If both networks claim:
10.10.0.x
routing becomes ambiguous.
10. Auto mode VPC warning
Two auto-mode VPC networks with their default subnets may have overlapping IP ranges.
Therefore:
They may not be able to establish VPC Peering because of overlapping subnet CIDRs.
11. No Transitive Peering
This is extremely important.
Suppose:
VPC-A | | Peering | VPC-B | | Peering | VPC-C
You might think:
A → B → C
means A can communicate with C.
❌ No.
VPC Network Peering does not support transitive peering.
So:
A ↔ B B ↔ C A ✕ C
A and C need their own direct peering connection if they need to communicate.
12. Why is this important?
Imagine:
CymbalBank1 ↙ ↘ / \ Bank2 Bank3
Bank1 is directly peered with:
- Bank2
- Bank3
But:
Bank2 ✕ Bank3
They cannot communicate through Bank1.
So:
Only directly peered VPC networks can communicate through VPC Peering.
13. How to create VPC Peering
Before creating the peering configuration, you need information about the other VPC.
If the other VPC is in another project, you need:
- Project ID
- VPC network name
Example:
My VPC: Cymbal-Rahway Other VPC: Cymbal-Kampala Other project: cymbal-10101
You then create a peering configuration pointing to that VPC.
But remember:
Creating the configuration on your side alone does NOT establish the connection.
The other VPC must also create its matching configuration.
14. Peering lifecycle
Think of it like this:
Step 1 VPC-A creates peering configuration ↓ INACTIVE ↓ Step 2 VPC-B creates matching configuration ↓ ACTIVE ↓ Subnet routes exchanged ↓ Private communication
15. Route exchange
After peering becomes active, the VPCs automatically exchange subnet routes.
Example:
VPC-A Subnet = 10.10.0.0/24 ↕ Peering VPC-B Subnet = 10.20.0.0/24
VPC-A learns:
10.20.0.0/24 → VPC-B
VPC-B learns:
10.10.0.0/24 → VPC-A
Therefore VM-A can communicate with VM-B using private IP addresses.
16. Custom routes
Sometimes automatically exchanged subnet routes aren't enough.
You may have custom routes or dynamic routes.
VPC Peering can be configured to:
- Import routes
- Export routes
- Import and export routes
Think:
VPC-A VPC-B Custom routes ───────→ Learn routes
The administrators on both sides must agree/configure the appropriate route exchange settings.
17. Dynamic routes + On-premises
This becomes particularly useful when your VPC connects to an on-premises network.
For example:
On-Premises | | VPN / Cloud Interconnect | VPC-A | | VPC Peering | VPC-B
VPC-A may know routes to the on-premises network.
With appropriate route exchange/configuration, the peered VPC can learn routes needed to reach on-premises resources.
18. VPN vs Cloud Interconnect
Cloud VPN
On-premises | | Encrypted tunnel | over Internet ↓ Google Cloud VPC
VPN provides an encrypted connection over the public internet.
Cloud Interconnect
On-premises | | Dedicated/private connectivity ↓ Google Cloud VPC
Cloud Interconnect provides a direct private connection between on-premises infrastructure and Google Cloud.
19. Cloud Router and dynamic routes
For dynamic routing scenarios, Cloud Router is involved.
You can configure custom route advertisements.
These advertisements tell the other network about routes/subnets that should be reachable.
Simplified:
On-Premises ↑ | routes Cloud Router ↑ | VPC-A | | Peering ↓ VPC-B
20. Route preference — important
The lesson mentions:
Local routes are preferred over dynamic routes learned through VPC Network Peering.
In simple words:
If your VPC already has a local route for something, Google Cloud prefers that local route instead of a dynamically learned peering route.
21. VPC Peering vs Shared VPC
These two concepts are easy to confuse.
VPC Network Peering
VPC-A ←──── Peering ────→ VPC-B
- Two separate VPCs
- Each remains independently administered
- Private connectivity
- Both sides configure peering
- No transitive communication
- No overlapping subnet CIDRs
Shared VPC
Host Project | Shared VPC / | \ / | \ Service Project Service Project VM VM
Shared VPC is designed for centralized network management.
The host project owns/manages the shared VPC, while service projects can use its network resources.
So the key difference is:
Peering = connect separate VPCs.
Shared VPC = centrally manage/share one VPC across projects.
🧠 Easy way to remember
VPC Peering
Think:
"Your network + my network, connected privately, but we still manage them separately."
Shared VPC
Think:
"One centrally managed network that multiple projects use."
No Transitive Peering
Think:
"A knows B, B knows C — that doesn't mean A knows C."
CIDR
Think:
"IP ranges must not overlap."
Two-sided configuration
Think:
"Both sides must agree before peering becomes ACTIVE."
⭐ Important points for your GCP revision
| Concept | Remember |
|---|---|
| VPC Peering | Private connectivity between VPCs |
| Same project? | Yes |
| Different project? | Yes |
| Different organization? | Yes |
| Internal IP communication | Yes |
| Both sides configure? | Yes |
| Peering state before both sides | Inactive |
| After matching configuration | Active |
| Subnet routes | Automatically exchanged |
| Firewall | Each VPC manages its own |
| Administration | Separate |
| CIDR overlap | Not allowed |
| Transitive peering | Not supported |
| Custom/dynamic routes | Can be imported/exported with configuration |
| On-prem connectivity | VPN / Cloud Interconnect |
| Dynamic routing | Cloud Router |
| Local route vs peering dynamic route | Local route preferred |
| Shared VPC | Centralized network management |
One-line architecture
VPC PEERING VPC-A ─────── Private Peering ─────── VPC-B ↑ ↑ Admin A Admin B Separate management Separate management
This section's main idea is: VPC Peering connects separate VPCs privately, but it does not merge or centrally manage them.
GCP Networking — Shared VPC
1. What problem does Shared VPC solve?
Suppose a company has multiple projects:
Project A → Recommendation Project B → Personalization Project C → Analytics Project D → Web
Each project could have its own VPC.
This can become difficult because the network administrator has to manage:
- Multiple VPC networks
- Firewall/security policies
- Access permissions
- New projects
- Network connectivity
- Scaling
The company wants:
Centralized network management + separate projects for workloads.
That's where Shared VPC comes in.
2. What is Shared VPC?
Simple definition
Shared VPC allows multiple projects to use a centrally managed VPC network.
There are two important types of projects:
Host Project
The host project owns the Shared VPC network.
Service Projects
The service projects use the Shared VPC network to deploy their resources.
Architecture:
Host Project | Shared VPC | ┌───────────┼───────────┐ ↓ ↓ ↓ Service Service Service Project A Project B Project C | | | VM VM VM
So:
Host project = owns/manages network
Service project = uses network and owns workload resources
3. Why use Shared VPC?
The main advantage is centralized networking.
Instead of:
Project A → VPC-A → Admin A Project B → VPC-B → Admin B Project C → VPC-C → Admin C
you can have:
Host Project | Shared VPC / | \ / | \ Project A Project B Project C VM VM VM
The network team centrally controls the network while different application teams can manage their own workloads.
4. Important: Network and workload are separated
This is one of the most important Shared VPC concepts.
Host project controls:
- Shared VPC
- Subnets
- Network configuration
- Network policies
- Network-level administration
Service project controls:
- VM instances
- Instance templates
- Managed instance groups
- Load balancers/resources
- Other workload resources
So you get:
Centralized network management + decentralized workload management.
5. Example from the lesson
Suppose:
Host Project "Web Application Servers" | | Shared VPC | ┌──────┼──────────┐ ↓ ↓ ↓ Rec. Personal. Analytics Project Project Project
The three service projects can create VMs using the shared network.
But the network itself is centrally managed from the host project.
6. Host Project
A project must be designated as the Host Project.
The host project:
- Contains the Shared VPC
- Controls the network
- Can attach service projects
- Can control which subnets are available to service projects
Example:
Host Project | └── Shared VPC | ├── subnet-a ├── subnet-b └── subnet-c
7. Service Projects
A Service Project is attached to the host project.
Its application teams can deploy resources into the Shared VPC.
Example:
Service Project A | └── VM | └── Shared VPC subnet
The VM belongs to Service Project A, but its network comes from the Host Project's Shared VPC.
8. Very important: Billing
The resource belongs to the service project.
For example:
Host Project | Shared VPC | └──── Service Project A | └── VM
The VM's billing is attributed to:
Service Project A
not the host project.
Easy way to remember:
Network → Host Project
Workload + billing → Service Project
9. Subnet-level sharing
The host administrator doesn't necessarily have to give every service project access to every subnet.
They can selectively share subnets.
Example:
Shared VPC │ ├── subnet-1 → Project A ✅ ├── subnet-2 → Project B ✅ └── subnet-3 → Project C ✅
This provides more granular control.
For example:
Service Project A ↓ Allowed to use 10.10.0.0/24 Cannot use 10.20.0.0/24
10. IAM roles in Shared VPC
Shared VPC relies heavily on Cloud IAM.
There are three important administrative levels from this lesson.
Organization Administrator
At the top:
Organization | Organization Admin
The organization administrator can nominate/configure administrators who will manage Shared VPC.
Shared VPC Administrator
The Shared VPC administrator performs tasks such as:
- Enable Shared VPC on the host project
- Attach service projects
- Grant access to subnets
- Delegate network usage permissions
A key role mentioned is:
compute.xpnAdmin
Remember:
XPN = Shared VPC terminology used by Google Cloud APIs/CLI.
Service Project Administrator
The service project administrator manages resources in their own service project.
For example:
Service Project | ├── VM ├── Instance Template ├── MIG └── Load Balancer
They need appropriate permissions, including the lesson's mentioned:
compute.instanceAdmin
11. compute.networkUser — very important
This role is particularly important for Shared VPC.
The Shared VPC administrator grants the Network User role so a service project/user can use particular Shared VPC subnets.
Conceptually:
Host Project | Shared VPC | └── subnet-1 ↑ | compute.networkUser | Service Project
Without appropriate network-user permission, the service project can't simply use the shared subnet.
Easy memory:
networkUser = permission to use the shared network/subnet.
12. Who creates the VM?
The service project administrator can create the VM.
Example:
Host Project | Shared VPC | subnet-1 ↑ | Service Project A | └── Create VM
The VM is:
- Created in Service Project A
- Billed to Service Project A
- Using a subnet from the Host Project's Shared VPC
13. Complete flow
The whole process can be understood like this:
1. Organization Admin ↓ Nominates Shared VPC Admin ↓ 2. Shared VPC Admin ↓ Select Host Project ↓ 3. Enable Shared VPC ↓ 4. Attach Service Projects ↓ 5. Grant networkUser permission ↓ 6. Service Project Admin ↓ Creates VM/resources ↓ 7. Resources use Shared VPC subnet
14. Shared VPC vs VPC Peering
This is very important because both appeared in this module.
| Feature | Shared VPC | VPC Network Peering |
|---|---|---|
| Main purpose | Share one VPC across projects | Connect separate VPCs |
| Network ownership | Host project | Each VPC owner |
| Network management | Centralized | Separate |
| Projects | Host + service projects | Independent projects |
| Private communication | Yes | Yes |
| Same organization | Yes | Yes |
| Different organizations | Shared VPC is organization-oriented | Peering can connect different organizations |
| Firewall/network administration | Centralized around host VPC | Each VPC manages its own |
| Transitive | Not the concept here | ❌ Not supported |
| CIDR overlap | Shared network uses same VPC | ❌ Peered VPC CIDRs cannot overlap |
The easiest distinction:
Shared VPC:
ONE VPC ↓ Many projects use it
VPC Peering:
VPC-A ←→ VPC-B
🧠 Real-world analogy
Imagine a company building.
Shared VPC
One central IT/network team manages the building's network.
Different departments have their own offices:
Central Network | ┌────┼────┐ HR IT Finance
Departments manage their own work, but the central team manages the network.
VPC Peering
Two separate companies/buildings have their own networks but establish a private connection:
Company A Network ←──── Private Connection ────→ Company B Network
Both companies continue managing their own networks.
⭐ Key points to remember for exams/labs
Shared VPC ↓ Host Project ↓ Owns Shared VPC ↓ Attach Service Projects ↓ Grant networkUser ↓ Service Projects create resources ↓ Resources use Shared VPC ↓ Billing → Service Project
Memorize these 5:
- Host Project owns the Shared VPC.
- Service Projects use the Shared VPC.
- Network management is centralized.
compute.networkUserallows use of shared subnets.- VM/resource billing belongs to the project where the resource is created.
And the big picture:
Shared VPC = centralized network + separated workloads across projects.
- Get link
- X
- Other Apps
Comments
Post a Comment