How to set up VPC Peering in Google Cloud Platform ?
VPC Peering is a concept using which O.S. in different VPC can communicate with each other using pvt IP’s through GCP owned high speed optical fiber network. It reduces cost, latency & improves performance to a great extent.
First of all let us try to create 2 different VPC’s
- VPC in Singapore region
VPC in US region
We can confirm VPC creation as below
Now let us try to launch instances in each of the above VPCs
Launching instance in S’pore region
In the networking we can attach to the “devvp”’ created initially.
Finally we can create instance
When we try to connect above instance using open web browser provided bu GCP, we can see the screen as follows
This connection will fail as we need to modify firewall rules.
by default instance will have following rules
Now we can successfully connect to instance as under
we can also install web server as follows
We can verify the Web site as under
In a similar fashion we can launch instance in other VPC which we have created.
Selecting the custom VPC for the instance
Modifying the firewall rules for “prod” instance launched above
We can test connectivity to “prod” instance through web browser as under
now let’s try to ping from “dev” instance to “prod” instance using ping command
We can see that ping doesn’t happen from “dev” instance to “prod” instance.
This can be resolved using VPC peering
For VPC peering we need to create peering connection as under
We should note the project id & vpc network name before creating VPC peering connection.
The status still shows inactive as we need to allow peering from other side as well i.e. from “prodvpc” to “devvpc” as well
and we can see that the “dev” instance is able to ping “prod” instance now
Thus, VPC peering helps to communicate instances in different VPC’s using private IP’s instead of public IP’s. Thus it’s more secure, high speed & reduces latency.