Deploying 2 Tier Application on Google Cloud

Sainadh
5 min readJun 9, 2021
@sainadh086

In this blog, you will learn about GCP, Kubernetes, VPC, MySQL database and deploying a 2-tier application.

Have you ever wondered how web applications running while placing the pre-order for the next gaming console Xbox or PlayStation, with the huge traffic flowing, the website is loading slowly, and we can’t place our order?

Here is the implementation of a website with GKE to overcome the issue.

The goal of this blog to implement the following

  1. Creating multiple projects in different regions.
  2. Connecting different projects via a private network.
  3. Creating a Kubernetes cluster and launching a web application with a load-balancer.
  4. Creating and connecting a SQL server database to the web application.

Google Cloud Platform (GCP)

GCP is one of the cloud providers, where they provide numerous services like Infrastructure, Networks, Solutions for Bigdata, AI, Machine Learning, app development and deployment environments.

Cloud environment is the way the applications are being deployed.

The major services they provide: -

  1. Infrastructure as a Service (IAAS)
  2. Platform as a Service (PAAS)
  3. Software as a Service (SAAS)

Creating multiple projects in different regions.

  • Create an account and login to the google cloud platform (GCP).
  • To work on any services provided by GCP you must create a project.
  • Create the first project I am calling it a developer project and the second project as production.
creating a project
  • Click on the project then create 2 projects, why we are using 2 projects because if you are developing a web service in India and most of the people using, your services are in America, so it is better to deploy our project in the American region and have a faster connection between 2 regions.
  • So, we can keep developer projects in India and production projects in America.
  • VPC peering connection is a networking connection between two VPCs (Dev & Prod) that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate with each other as if they are within the same network.
  • A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate with each other as if they are within the same network.
  • A virtual private cloud (VPC) is an on-demand configurable pool of shared computing resources allocated within a public cloud environment, providing a certain level of isolation between the different organizations using the resources.
  • Do this for both the projects (Developer & Production).
creating a VPC

We need to create a custom firewall (security system) to allow egress (outgoing network) for HTTP protocol for both projects. like this, we can create as many firewalls as we want based on the requirement.

create a firewall

Now you have connected both the projects over a private network.

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, which facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

Now we create a Kubernetes cluster for auto-scaling, easy deployment, fault tolerance, and maintenance.

Kubernetes has an object called a pod. Pod is a primary object where it runs containers. Without pods, you can’t do anything in Kubernetes.

creating a Kubernetes cluster

Here we created a Kubernetes engine to create our web application and deploying. By default, it will create 3 nodes, we can also scale up to n number of nodes.

Some of the basic Kubernetes commands we can use for creating a website with WordPress docker images or any docker image.

Kubectl is the command line tool kit and responsible for creating, deleting, and updating the containers in Kubernetes.

Kubernetes objects are the persistent entities in the Kubernetes system. They describe the state of containers created in the system.

$ gcloud projects list(lists all the projects our GCP)PROJECT_ID NAME PROJECT_NUMBERdevproject-11611969 devproject 1094276842375driven-heading-287204 My First Project 388675543869dulcet-basis-287204 My First Project 919653102650indigo-bazaar-287204 My First Project 223126735644malepatideveloper malepatideveloper 823895353409malepatiproduction malepatiproduction 286017288695omega-healer-287204 My First Project 485070081903$ gcloud container clusters list — project malepatideveloper 
#Shows containers list in our project
$ kubectl get pods # provides the list pods#Deploying a wordpress image$ kubectl create deployment mywp --image=wordpressdeployment.apps/mywp created$ kubectl get pods #(for checking the pods)NAME READY STATUS RESTARTS AGEmywp-86b6ff5d8b-22mqz 0/1 ContainerCreating 0 11s$ kubectl get deploy (For deploying)$ kubectl expose deploy mywp — type=LoadBalancer — port=80 (deploying our web services with load balancer at port number 80)$ kubectl get services #(To check the services)NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.192.0.1 <none> 443/TCP 26mmywp LoadBalancer 10.192.13.42 35.194.34.149 80:31930/TCP 66s

We have successfully deployed our WordPress website in the developer project.

Now we create a MySQL Database for storing the data and connect it to the WordPress website in the production project.

MySQL is a database management system, with Structured Query Language (SQL) support. It is an opensource project.

creating MySql Database
database

Now we connect to our website with our public ip highlighted running

$ kubectl get services 
#here you can see the services which are exposed to internet (35.194.34.149:80)

Then we setup the website and login to the website in this process we can connect to the SQL server.

And posted our first blog.

Thus, we created our VPC in GCP, MYSQL database, and created a Kubernetes cluster.

Conclusion: - You have learned how to create a Kubernetes Cluster, VPC peering, MySQL Database, and working on GCP.

Thank you for reading the blog if you have any doubts comment below. Stay tuned for more blogs on DevOps tools.

To read about Jenkins an opensource automation tool [click_here].

--

--

Sainadh

Devops and automation export, explorer, opensource enthusiast, follow for more content related to devops and easy way to do the things.