After two days of successful workshop on Google Cloud Platform(GCP) Mr.Vimal Daga, Now it’s time to Launch a webserver on Google Cloud with Kubernetes and LoadBalancing and connects with SQL database.

So let’s understand first what gonna happen throughout the projects:-

  1. Their would be two projects namely: developer and production
  2. Their would be two two VPC network for each projects.
  3. Create a link between both the VPC networks using VPC Peering
  4. Create a Kubernetes Cluster in developer project and launch any web application with the Load balancer
  5. Create a SQL server in the production project and create a database.
  6. Connect the SQL database to the web application launched in the Kubernetes cluster.

Ok so let’s get started…….


Creating two projects

Open Google Cloud Console and go to create new project give the name as developer and create.

Again go to dashboard and create new project with name as production and create.

Now we can see our projects in projects section. Choose the developer project

Creating Two VPC Network

For doing so we must have Compute Engine API Enabled as

for enabling this just go to

menu>API-and-Services>Library>Compute>Compute-Engine API and enable this.

Now from menu go to the networking section and choose VPC network after selecting the VPC network their would be default network listed just click on create VPC network.

Now add fields VPC name, subnet name, Region and ip ranges and create as shown.

Now change the project from above bar to production, enable the Compute Engine API and go to VPC network in Networking section and create new vpc network with name productionvpc.

Also we have to create a firewall on both the project for the network where we will decide that from which ip ranges it is accessable for this task we will allow all ip ranges(but in real use case we don’t do so)

for creating firewall rules go to

VPC_Network>choose_our_created_newtwork>firewall_rules and add firewall rules as shown below.

Link between both the VPC network using VPC peering

Now for VPC peering go to menu>VPC_Network>VPC_Network_Peering

Now it would ask for create connection and just go for that click continue after that and fill the field with name VPC network name and choose in other project(we can choose the same project but in this task we are peering with network that is on other project so) and give the project id with VPC network of that project. As shown below

After clicking on create it will create the peering but it will show the status as inactive because we have to do same on other network too.

So just jump on another project that is on developer and create VPC peering. Give project id of the same project to which we wants to peer and VPC network name of that project.

Now you can see the status would changed to active on both project if this is so then your peering is successful.

Now create a VM Instance on both the projects under same VPC network. For ensuring peering is successful or not launch one of the os in ssh browser and try to ping on private ip if it is pingable then for sure peering is done.



AS you can see the private ip we will use this to ping

This is pingable Now

So we have successfully link both the VPC network.

Create a Kubernetes Cluster in developer project and launch any web application with the Load balancer

Here we will launch wordpress as web application with Kubernetes and LoadBalancer. So first go to menu>kubernetes_cluster and create a cluster first it will enable kubernetes API automatically and gives a option to create a cluster go for that in devproject.

Select Machine type in Node pool and create.

After creating is done we get the below screeen go to connect option

Now we get the below screen copy the command

Now we have to run this in our cloud shell or local terminal. For running in local terminal we have to install first kubectl and gcloud sdks in pc. So for installing that just visit the google and search for kubectl install and gcloud install choose the option accordingly of your pc type.

For kubectl
For gcloud

Now open your local terminal and paste the copied part from cluster.

Launch the web app with the image name and cmd as follows

kubectl created deploy/deployment os_name — image=image_name here we can get the image name from hub.docker.com using wordpress here

Docker Image
Creating pod

Now for getting nodes details run the command kubectl get nodes

Get pods

get the launched pods information with command kubectl get pods.

we scale the pods with command kubectl scale deployment/deploy os_name — replicas=N where N is any number

Scaling

we can get more information about pods with command kubectl get pod -o wide

More details of pods

Now time to add loadbalancer in our cluster for doing so run the command kubectl expose deploy os_name — type=LoadBalancer — port=80 it will create a loadbalancing on Google cloud Platform that can be seen by going to menu>Network and services

Exposing with LoadBalancer

Create a SQL server in the production project and create a database.

Now jump to the second project namely production and go to menu>SQL>mysql and create instance

Now it will be landed to the below page in which go to database create a database with any name(I’m creating with mydb1) and go to connection under which add network where just allow all by writing ip as 0.0.0.0/0(it’s not safe but for this task I’m doing).

Creating DataBase
Allowing all

after that just copy the Public IP of instance.

Now again come to terminal and write command as kubectl get services the output what we get just copy the public ip and paste in address basr of browser.

Copy the external IP
It will open this page

Click continue

It is asking for connect the database. so click on let’s go.

Now Give the database name, username, password of user and host name(here host name will be the IP of SQL instance)

Connecting Database

Now It would ask for installation go for that.

Fill the required fields.

Running Installation

Now Login with created username and password

Login

After Login it would open Dashboard now by going to posts section we can see our created pages

DashBoard
Posts

Now we can check the DataBase by launching the SQL instance in cloud shell and giving the password.

Cloud Shell

Use command show databases; to see the all the databases

Databases

for using specific database use the command use database_name; I’m using mydb1 here

Changing DataBase

Use command show table_name; to view table

Showing tables

That’s it all done.

Thank you for reading

Please leave me your valuable feedback..

connect me on linkedin