VPC Peering In GCP & Launch Frontend(Wordpress) in GKE And Connect our frontend to Backend(SQL db)
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).
Same concept we will use in different project (saraswat-948)and create one more VPC with name myprodvpc
3-Launch instances in Both VPC-
We will launch the instance in saraswat-948 project in vpc myprodvpc
We can connect our instance using ssh protocol.
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.
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.
Now we can connect our instance using ssh
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
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-
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
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.
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.
To connect our cluster GCP provide us a command run it on your command prompt
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
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
8- Launch your sql database in GCP
Now we will launch our database in GCP
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
Finally everything is working properly you can use it.
Thanks for reading
Thanks to Vimal Daga Sir.