Deployment Of Web Application with Database On The Top Of GCP Cloud

Sathvika Kolisetty
7 min readAug 31, 2020

In this task, we will learn how to launch a Website on the top of the GCP Cloud by integrating it with multiple resources.

Problem Statement

1. Create multiple projects namely developer and production

2. Create a VPC network for both the 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

What is Google Cloud?

Google’s cloud platform provides a reliable and highly scalable cloud computing services to its users. These services help clients compute and store data, and help developers build, test, and deploy apps. Google cloud covers application, storage, and cloud computing services for backend, mobile, and web solutions using the internet. More than four million apps trust and use this platform.

What is Vpc?

Google Cloud VPC is global, scalable, and flexible.VPC is like a building and under that we setup environments like labs ie., Subnets and for security purposes, we can use firewall also. Virtual Private Cloud ( VPC) enables you to launch resources into a virtual network that you’ve defined.

What is Subnet?

A subnetwork (also known as a subnet) is a logical partition of a Virtual Private Cloud network with one primary IP range and zero or more. Every Subnet defines a range of Ip addresses in your Vpc.

What is VPC Peering?

A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using Ip address connectivity. It also allows internal IP address connectivity across two Virtual Private Cloud (VPC) networks regardless of whether they belong to the same project or the same organization.

What is Kubernetes?

Kubernetes is an open-source container platform that eliminates many of the manual processes involved in deploying and scaling containerized applications. Through Cluster, we can manage the instances when it goes down.

What is a Pod?

A pod is a collection of containers and its storage inside a node of a Kubernetes cluster and mount namespace and is the basic unit of deployment in Kubernetes.

As per mentioned in the problem statement we have to create multiple projects but as I’m doing in qwiklabs I’ll be doing the entire task in the same project.

Let’s get started

First, go to the GCP console and then open the services list and click on VPC Network, In this task, I’m going to create two VPC’s one for developer environment and the other for production environment in Singapore(Asia-southeast1) and Los Angeles (US-west2) respectively with one subnet in each.

Vpc for developer env

Subnet for developer env

Vpc and subnet for production env

VPC for two different environments created successfully

For this first, go VPC network and then select vpc peering then follow the steps mentioned below

Let’s create the connection from dev-vpc first to prod-env

But if you see the status of connection it will be inactive. If you want it actively connect to the other vpc, we should also create the same as above in that vpc to accept a connection.

And now if you see, the connection is activated.

Creating a Kubernetes cluster in Developer env

What is GKE?

Google Kubernetes Engine or “GKE” is a Google-managed Kubernetes environment. GKE is a fully managed experience; it handles the management/upgrading of the Kubernetes cluster master as well as autoscaling of “nodes” through “node pool” templates. Through GKE, your Kubernetes deployments will have first-class support for GCP IAM identities, the built-in configuration of high-availability and secured clusters, as well as native access to GCP’s networking features such as load balancers.

Let’s create a Kubernetes cluster on GCP using Google Kubernetes Engine (GKE):

For this first click on GKE and cluster from selection now click on create cluster..and follow the same as below

Now finally configure the network details,i.e vpc and subnet where the cluster to be launched. here I’m launching in the developer vpc.

Now, if you see the cluster has been successfully created in Singapore region.

we need to set up the Kubernetes client using the package called “kubectl”.Here I’m using my cloud shell itself as Kubernetes client and hence I set up kubectl in it.

Setting up K8’s client within the cloud shell

For this we need to follow three simple commands or steps as below, then everything is done.

  1. Download the latest release with the command:
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"

2. Make the kubectl binary executable.

chmod +x ./kubectl

3. Move the binary into your PATH.

sudo mv ./kubectl /usr/local/bin/kubectl

That’s done …confirm it by verifying the version of Kubernetes using the cmd:

kubectl version --client

Now let’s connect to the cluster using cloud shell

For this, you have to go to clusters and click on connect on the cluster you created, it will popup a window like this

Copy the command line access link and paste it in the cloud shell to register the cluster with kubectl and to verify run some commands as follows to check the nodes present in the cluster.

Here, I’m using the wordpress as web app and using its docker image I’m launching a pod of wordpress using deployment also expose it outside world using the internal load balancer of the GCP. There is no load balancer created in prior but after we expose deployment a load balancer is created automatically internally.

From the commands itself. you know that a pod has been created and the service with type Load Balancer has been created.

Now, using the load balancer Ip we can connect to the wordpress site…but before going to that we know that wordpress being a frontend requires the backend to store all its data. For that, we will create a MySql database using SQL service provided by the GCP.

Creating a MySql database for wordpress using SQL service

For this, firstly we need to go for SQL service and create an instance

Now, I'm going to configure instance details and creating it in the region LosAngeles…also setting the root password too.

Now, if you try to use the database it won’t work ..why because we haven’t set any firewall rule so that someone should use this database. We can create the firewall rule as follows..for this we first go to connections and apply as below.

Now save the changes and next, we have to create a database for the wordpress. For this first, go to the databases and click on create a new database, provide the name and save it..see below.

That’s it everything has been done perfectly and now we use the load balancer IP to connect to the Wordpress site and use the Mysql instance IP and database created as backend host configuration details

Let’s start with configuring the wordpress site.

--

--