VPC Peering In GCP & Launch Frontend(Wordpress) in GKE And Connect our frontend to Backend(SQL db)

Mohd Sabir
7 min readAug 29, 2020

--

What is GCP?

GCP (Google Cloud Plateform) is a Public Cloud. It offered by Google. Google Cloud Platform provides Infrastructure as a service (IaaS), Platform as a service (PaaS) , Serverless computing environments.

Objective for this task:-

1- Create two Project In GCP

2- Create two VPC in different-2 Project

3- Launch instances in Both VPC

4- Create VPC peering in both Project

5- Create K8S cluster using GKE service.

6- Launch Wordpress Pod

7- Create a Load balancer

8- Launch your sql database in GCP

9- Connect your Wordpress to your database

Let’s start our task:-

Prerequisite for this task:-

1-GCP Account

2- Install and setup kubectl

1- Create two Project In GCP

Go to your gcp console and login it by default when you create a account they create a project for you. For creating new project you have to select project and then click on new project.

Finally Our project Dev-69261 Created using same steps i have create one more project saraswat-948.

2- Create two VPC in different-2 Project-

Firstly select your project where you want to create vpc then go to networking select vpc network ,

when we use any service first we have to enable API (Application Program Interface).

click on Enable..
click on CREATE VPC NETWORK.
Finally VPC created mydevvpc

Same concept we will use in different project (saraswat-948)and create one more VPC with name myprodvpc

finally second vpc created myprodvpc

3-Launch instances in Both VPC-

We will launch the instance in saraswat-948 project in vpc myprodvpc

we can select as per our requirement like which operating system we want to select like which operating system, machine type etc.
here we will select myprodvpc
our instance has been launched succesfully.

We can connect our instance using ssh protocol.

click on open in browser window
showing message could not connect

They are not connecting because there is a firewall & firewall is not allowing to connect ssh. we have not create any firewall rule in our vpc.

go to your vpc and click on firewall rules
there is no firewall rules

firstly we have to create firewall rules

Here I allow to anyone can connect but it’s not good for security you can allow particular ip.

finally firewall rule created

Now we can connect our instance using ssh

Now they are connecting
finally they connected

this above Instance i have launch in saraswat-948 project and myprodvpc

Using same above steps I created one more instance in Dev-69261 project and vpc mydevvpc

finally launched

If we have use case we want to share some data from prodos to devos we have two option either we can use public network or private network of GCP, If we are using public network data transfer speed will be slow and some security risk. If we want to overcome these issue so we need to use private network of GCP. To connect two instance privately from different project we have a service in GCP name VPC PEERING.

4- Create VPC peering in both Project-

Click on vpc network peering
Click Create Connection
If your instance is running in different project select in another project if in same project then you can select in project

In saraswat-948 project your vpc peer connection created but it is inactive. when you create in vpc peer connection in another project automatically it will active

Now we will create vpc peer connection in different project using same above steps

You can see here its showing active automatically because we have already create vpc peer coneection in different project. Now if you will see in another Is it active or not we can

Now it is active

Now our VPC peer connection establish successfully in both side now we can transfer our data privately using google network. How to check our connection is establish properly or not , we can check using ping command if both instance is pinging properly it means connection establish succesfully

both instance

Private IP of both is prodos-10.0.2.2 , devos-10.0.0.2

Now finally they are pinging to each other.

5- Create K8S cluster using GKE service-

GKE( Google Kubernetes Engine ) is fully managed kubernetes service of GCP.

Click Create Cluster

If we are creating k8s cluster we have to plan it like how many nodes we need & configuration of nodes.

Here we can create a node pool either we can edit default node pool as per our requirement.

Node Configuration detail
Finally our cluster launch

To connect our cluster GCP provide us a command run it on your command prompt

In black box is command
I run this command on my cmd promt
finally our cluster is connected

Now we can check how many pods , nodes is runing using kubectl command

  • kubectl get pods ( to check pods)
  • kubectl get nodes ( to check nodes)

6- Launch Wordpress Pod-

Now we will launch wordpress pod using

  • Kubectl create deployment myweb — image=wordpress
Finally our pod is created

7- Create a Load balancer-

Now we will create a load balancer to connect our wordpress pod using

  • kubectl expose deployment myweb — type=LoadBalancer — port=80
you can check through web UI loadbalncer created

8- Launch your sql database in GCP

Now we will launch our database in GCP

Click Create Instance
Here I will MySql (you can select as per your requirement)
Finally our databse ready

You can create database using webui and cli , I have created lwdb databse.

9- Connect your Wordpress to your database-

Get your Load balancer ip using command

  • kubectl get services
  • copy your load balancer ip and paste it on browser
fill all the detail than submit
Now your wordpress installed properly
login than use

Finally everything is working properly you can use it.

Thanks for reading

Thanks to Vimal Daga Sir.

--

--

Mohd Sabir
Mohd Sabir

Written by Mohd Sabir

DevOps Enthusiastic || Kubernetes || GCP || Terraform || Jenkins || Scripting || Linux ,, Don’t hesitate to contact on : https://www.linkedin.com/in/mohdsabir

No responses yet