VPC Network Peering
VPC Network Peering setup
In this lab you have been provisioned 2 projects, the first project as a Project A and second as Project B.
Project-A:
- Go back to first cloud shell and create a custom network:
gcloud compute networks create network-a --subnet-mode custom
- Create a subnet within this VPC and specify a region and IP range by running:
gcloud compute networks subnets create network-a-central --network network-a --range 10.0.0.0/16 --region us-central1
- Create a VM instance:
gcloud compute instances create vm-a --zone us-central1-a --network network-a --subnet network-a-central
- Run the following to enable SSH and icmp, because you’ll need a secure shell to communicate with VMs during connectivity testing:
gcloud compute firewall-rules create network-a-fw --network network-a --allow tcp:22,icmp
Project-B:
- Switch to the second cloud shell and create a custom network:
gcloud compute networks create network-b --subnet-mode custom
- Create a subnet within this VPC and specify a region and IP range by running:
gcloud compute networks subnets create network-b-central --network network-b --range 10.8.0.0/16 --region us-central1
- Create a VM instance:
gcloud compute instances create vm-b --zone us-central1-a --network network-b --subnet network-b-central
- Run the following to enable SSH and icmp, because you’ll need a secure shell to communicate with VMs during connectivity testing:
gcloud compute firewall-rules create network-b-fw --network network-b --allow tcp:22,icmp
Setting up a VPC Network Peering session
Project-A – Peer network-a with network-b:
Go to the VPC Network Peering
 in the Cloud Console by navigating to the Networking section and clicking VPC Network > VPC network peering in the left menu. Once you’re there:
- Click Create connection.
- Click Continue.
- Type “peer-ab” as the Name for this side of the connection.
- Under Your VPC network, select the network you want to peer (network-a).
- Set the Peered VPC network radio buttons to In another project.
- Paste in the Project ID of the second project.
- Type in the VPC network name of the other network (network-b).
- Click Create.
Project-B – Peer network-b with network-a:
- Click Create connection.
- Click Continue.
- Type “peer-ba” as the Name for this side of the connection.
- Under Your VPC network, select the network you want to peer (network-b).
- Set the Peering VPC network radio buttons to In another project, unless you wish to peer within the same project.
- Specify the Project ID of the first project.
- Specify VPC network name of the other network (network-a).
- Click Create.
Connectivity test
Project-A
- Navigate to VM instances console: Click Navigation Menu > Compute Engine > VM instances.
- Copy the INTERNAL_IP forÂ
vm-a
.
Project-B
- Click Navigation Menu > Compute Engine > VM instances.
SSH intovm-b
 instance.
- In the SSH shell ofÂ
vm-b
, run the following command replacingÂ<INTERNAL_IP_OF_VM_A>
with the vm-a instance INTERNAL_IP:ping -c 5 <INTERNAL_IP_OF_VM_A>
Tag:Google Cloud