🌐 How to Create VPC Peering in GCP
Learn how to set up VPC Network Peering in Google Cloud Platform and understand its benefits and limitations.
VPC Peering in Google Cloud Platform (GCP) is a networking feature that allows you to connect two Virtual Private Cloud (VPC) networks. This connectivity happens privately, using internal IP addresses, and ensures that traffic does not traverse the public internet. VPC Peering enables secure, high-performance communication between workloads in different VPC networks, which can be within the same project, across different projects, or even between different organizations.
🔍 What is VPC Peering?
Google Cloud VPC Network Peering enables internal IP address connectivity between two VPC networks. These networks can exist within the same project or organization, or across different projects and organizations.
With VPC Peering:
- Traffic stays within the Google backbone network and does not traverse the public internet.
- Lower latency is achieved due to direct internal communication.
- It reduces egress communication costs compared to external IPs.
- Services remain secure by avoiding public internet exposure.
👉 For official documentation, visit Google Cloud VPC Peering.
🚀 Benefits of VPC Network Peering
- 🔒 Enhanced Security: Traffic remains private and avoids public internet exposure.
- ⚡ Low Latency: Internal IP connectivity ensures faster communication.
- 💰 Cost-Efficient: Eliminates external IP costs for cross-VPC communication.
- 🔧 Flexible Use Cases: Works with Compute Engine, Google Kubernetes Engine (GKE), and App Engine.
🚀 Why Use VPC Peering?
- Low Latency: Traffic between peered networks uses Google’s high-speed private backbone.
- Cost-Efficient: Internal IP traffic avoids the costs associated with using external IP addresses.
- Improved Security: Communication does not traverse the public internet, reducing exposure to risks.
- Scalable Connectivity: Simplifies connections between VPCs in the same or different projects.
- Flexible Architecture: Works seamlessly across Compute Engine, Kubernetes Engine (GKE), and App Engine.
🚀 How Does VPC Peering Work?
VPC Peering establishes a direct connection between two VPC networks. Once peered:
- Resources (e.g., VM instances, Kubernetes pods, or databases) in one VPC can communicate with resources in the other VPC using internal IP addresses.
- Both VPCs must configure the peering association for it to become active. This is a bidirectional configuration where each VPC allows the peering.
🛠️ How to Create VPC Peering in GCP
Follow these steps to set up VPC Peering between two VPC networks in GCP:
🔹 Step 1: Pre-requisites
- Ensure you have two VPC networks:
- VPC A with a subnet CIDR range `10.0.0.0/16`
- VPC B with a subnet CIDR range `10.8.0.0/16`
- Each subnet should have a Google Compute Engine instance for testing private IP connectivity.
- You need IAM permissions: `roles/editor` or `roles/compute.networkAdmin`.

🔹 Step 2: Create Peering Connection from VPC A to VPC B
- Navigate to the [VPC Network Page](https://console.cloud.google.com/networking/networks) in the Google Cloud Console.
- Select VPC A (e.g., `network-a`) and click Create Peering Connection.
- Provide the following details:
- Peering Name: Example: `vpc-a-to-b`
- Peer Project ID: The project ID of VPC B.
- Peer VPC Name: The name of the target network (VPC B).
- Enable Import and Export of Custom Routes.
- Click Create Peering Connection.
At this stage, the peering connection is in an INACTIVE state.
🔹 Step 3: Create Peering Connection from VPC B to VPC A
At this point, the peering connection is INACTIVE until VPC B creates a matching peering configuration.
- Navigate to VPC B (e.g., `network-b`) and click Create Peering Connection.
- Provide the details:
- Peering Name: Example: `vpc-b-to-a`
- Peer Project ID: The project ID of VPC A.
- Peer VPC Name: The name of the target network (VPC A).
- Enable Import and Export of Custom Routes.
- Click Create Peering Connection.
Once both peering connections are configured, the peering status changes to ACTIVE.

🔹 Step 4: Verify the Peering Connection
Once both peering configurations are created, the status should become ACTIVE.
- In the Google Cloud Console, go to the VPC Network Peering page.
- Check the status of the peering connections for both VPC networks.
- Verify that routes and subnets are exchanged successfully.
🔹 Step 5: Test Connectivity
- SSH into a VM in VPC A.
- Ping the private IP of a VM in VPC B:
ping 10.8.0.2 - If the peering is successful, you will see a response.
🚀 Key Features of VPC Peering
- Internal IP Connectivity: Enables communication using private IP addresses between VPCs.
- Global Reach: Supports VPC networks within the same or different regions.
- Custom Route Exchange: Allows sharing of custom routes between VPC networks.
- Flexible Setup: Supports VPC peering within the same project, across projects, or across organizations.
- No Single Point of Failure: VPC Peering is a fully distributed system and does not rely on a single gateway or router.
⚠️ Important Considerations for VPC Peering
- 🚫 Subnet Overlap: CIDR ranges of peered VPCs must not overlap.
- 🔄 No Transitive Peering: VPC A peered with VPC B and VPC B peered with VPC C does not mean VPC A is peered with VPC C.
- 🔗 Maximum Connections: A single VPC can have a maximum of 25 peering connections.
- 🛑 Deleting a VPC: Remove all peering configurations before deleting a VPC.
🚀 VPC Peering Use Cases
- Multi-Project Deployments:
- Organizations running workloads across multiple projects can use VPC Peering to enable private communication between VPCs.
- Shared Services:
- Centralized services such as monitoring, logging, or databases can be shared across VPCs using peering.
- Hybrid Cloud Environments:
- Connect on-premises systems with Google Cloud networks.
- Microservices Architecture:
- Decouple applications by placing services in different VPCs while ensuring private communication.
- Cost-Optimized Inter-VPC Communication:
- Avoid external IPs to reduce network egress costs.
🚀 VPC Peering vs Other Connectivity Options
| Feature | VPC Peering | VPN | Shared VPC |
|---|---|---|---|
| Latency | Low (internal traffic) | Higher (over public IP) | Low (internal traffic) |
| Setup Complexity | Easy | Moderate | Complex |
| Internet Exposure | No | Possible | No |
| Custom Routes | Supported | Limited | Supported |
| Use Case | Private VPC communication | Hybrid connectivity | Multi-project networking |
🎯 Real-World Use Cases of VPC Peering
- 🚀 Multi-Project Deployments: Connect VPCs across projects for shared resources.
- 🔒 Secure Communication: Enable private communication between services without public IPs.
- 💰 Cost Optimization: Reduce costs by using internal IPs for inter-VPC traffic.
