How to deploy a database & wordpress on the top of Google Cloud Platform ( GCP )

Hello everyone , again i come up with another article on how to use Google Cloud Platform , to deploy our database & any frontend site or server as like any webserver or anything else. This article include all the process & prerequisite to perform this task.

Before doing any practical we have to know some basic knowledge about that technology , so that anyone can admire our knowledge & thought process. So first we have to know about the what is the google cloud platform why do we use it ?

Image for post
Image for post

What is Google Cloud Platform ( GCP ) ?

Google Cloud is a suite of Cloud Computing services offered by Google. The platform provides various services like compute, storage, networking, Big Data , and many more that run on the same infrastructure that Google uses internally for its end users like Google Search and YouTube.

Google server hasn’t gone down in years. So, if you are planning to run your application on the Google Cloud infrastructure, then you can be assured of your applications being safe and secure.

Why Google Cloud?

Google Cloud has been one of the top cloud providers in the IT industry. The services they offer can be accessed by software developers, as it provides a reliable and highly scalable infrastructure to build, test, and deploy their applications.

Best Pricing: Google Cloud hosting plans are cheaper than other platforms’ hosting plans. Google Cloud offers to its customers the pay-as-you-go feature where the users only have to pay for the resources they use.

Work from Anywhere: Employees gain complete access to information across devices from anywhere in the world through web-based applications powered by Google.

Private Network: Google provides its own network to every customer so that they have more control and scalability over the network. It uses fiber-optic cables to spread its network, as they tend to bear any amount of traffic. Users get maximum time and efficiency due to this private network.

Security: Google has hired a large set of security professionals who help in protecting the data on servers. All data on the Cloud platform is encrypted. So, users can be sure of their data being safe and secure.

Redundant Backup: Google has its own in-built redundant backups. So, if the data stored by the user is lost, then Google would have created a backup for it. So, your data is technically not lost! Redundancy helps ensure data integrity, reliability, and durability.

So here i want to discuss about the some services provide by the GCP that will used by me to performing this task. So the services are followings:

Compute Services:

  • Compute Engine: Infrastructure as a Service to run Microsoft Windows and Linux Virtual Machine. It is a component of the Google Cloud platform which is built on the same infrastructure that runs Google’s search engine, YouTube, and other services.
  • Kubernetes Engine: It aims at providing a platform for automating deployment, scaling, and operations of application containers across clusters of hosts. It works with a wide range of container tools including docker.

→ Storage Services

  • Google Cloud Storage: An online file storage web service for storing and accessing data on a Google Cloud platform infrastructure. The service combines the performance and scalability of Google Cloud with advanced security and sharing capabilities.
  • Cloud SQL: A web service that allows you to create, configure, and use relational databases that live in Google Cloud. It maintains, manages, and administers your databases allowing you to focus on your applications and services.

→ Networking

  • VPC: Virtual Private Cloud provides a private network with IP allocation, routing, and network firewall policies to create a secure environment for your deployments.
  • Cloud Load Balancing: It is a process of distributing workloads across multiple computing resources. This reduces the cost and maximizes the availability of the resources.

So while doing this we need the kubernetes services provide the deploy our wordpress pods , so we have to know some basic concepts of the kubernetes.

What is Kubernetes ?

Kubernetes is an open-source system that allows organizations to deploy and manage containerized applications like platforms as a service (PaaS), batch processing workers, and micro services in the cloud at scale. Through an abstraction layer created on top of a group of hosts, development teams can let Kubernetes manage a host of functions — including load balancing, monitoring, deployment , providing the storage and controlling resource consumption by team or application, limiting resource consumption and leveraging additional resources from new hosts added to a cluster, and other workflows.

We can use kubernetes on our local system as well as on the top of cloud also . So in this task we are using the cloud to deploy our app or website on it.

So now before performing the task we have to know about the whole task.

Task Description :

1. Create multiple projects namely developer and production.

2. Create 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.

Now we will start the task & i will discuss all the step by step process or method to perform this task.

Step 1: Create two projects one for developer & another for production.

Create one project for the developer from where developer can work in their our own projects.

Image for post
Image for post

Create one project for the production department from where production guys can work in their our own projects.

Image for post
Image for post

Now you can see that there is two projects is created & you can verify the projects.

Image for post
Image for post

When we create a project we want to use it for our purpose but , for this we have to enable the billing for the projects that is created by me. So it means when we create any projects its billing service had disabled so we have to enable it. So now we are enabling the billing for respective projects.

From the above image we can verify that our projects have enabled billing.

Step 2: Create a VPC network for both the projects.

So if you have ever work on any cloud like AWS so if you want to use the any service there you can use that service directly , but in GCP cloud if we want to use any service then first we have to create the projects & after that we have to enabled the API for that service , like i have done in my projects.

Image for post
Image for post

Here you can see that i have already enabled the API for VPC and it is for the devprojects.

Now in similar way we will do the same process for the prodprojects.

Image for post
Image for post

You can see that for this projects we have not enable the API services for the prodprojects , so we have to enable that then we will use the that services.

Image for post
Image for post

Now you can see that i have enabled the API for compute engine , because we have to create a VPC for the both the network so we enabled the API for both projects.

Now, firstly we will create the VPC for prodprojects.

Image for post
Image for post

After click on the create VPC network then we will create the network according to our requirements.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

As you can see that we have created a VPC network for the Prod projects , as per the desired . So in the similar way we will create a VPC network for the Dev projects , so that we can use the dev projects outside to our system.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

So here you can see that we have created the vpc network for the dev project as per our desired so that we can use it according to the our use case or as per our prospective.

Now next task is to establish the connection between the both the network.

→ Step 3: Create the VPC peering for both the network.

Image for post
Image for post

Here you can see that there is not a single vpc peering has been created yet , so we are going to create the vpc peering for the prod project.

Image for post
Image for post

When we click on the create button it will create the vpc peering for the prod project.

Image for post
Image for post

Now you can see that vpc peering for the prod projects has been created but it is in inactive mode because the peering connection will established only when , if the other projects has also one vpc peering then the status will be active.

So in the similar way we will create a vpc peering foe the dev projects also ,so that we can established the connection between both the network.

Image for post
Image for post
Image for post
Image for post

Here you can find that vpc-peering for the dev projects has been created & you can also find that the status is active for the vpc peering.

Whenever we use any technology or a tool , we can use it by two ways either from GUI or either from CLI . So we know that we are human beings and we are always comfortable with the GUI , but it is always a good practice to know about the how to use any program from the CLI , so similarly foe google cloud platform we have CLI availbale ,if we want to use the same then we have to install the SDK for the gcloud. So first we have to download the software & then we can proceed with the CLI.

We can download the software from the given link: https://cloud.google.com/sdk/docs/quickstart-windows

Image for post
Image for post

Once you click on the google cloud SDK installer the software will downloaded and just we have to install it & use it.

So after the installation part if we want to use the gcloud from the CLI then you can use it , but only condition is that you have to successfully installed the software or program.

Image for post
Image for post

Here you can see that my gcloud command is working fine and i run the command “gcloud projects list” to check the projects and it is working properly.

→ Step 4: Create the kubernertes cluster & launch the Kubernetes pods.

As we had already mentioned that we have to deploy a web server on the top of google cloud , so to do this task we have to use the google kubernetes engine service , so we will use the same for that , but we now that if we want to host a web server we can host the server through a pods only & also using the deployment , but it is always a good practice to launch all these things inside a cluster so that we can use the cluster to deploy the server. So we are going to create a kubernetes cluster on the top of google cloud platform.

Image for post
Image for post

As you can see that we have not created any cluster on the top of gcp, so we are going to create it. But we know one thing that if we want to use any service then we have to enable the API service for that , so here you can see that API services has enabled by me already.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Now we will click on the create & our Kubernetes cluster will created and it will configured according to the given instruction.

Image for post
Image for post

So now after creating the cluster we have to use our command prompt for the further process , so to connect your local command prompt to the kubernetes cluster that has created on gcp , so as you can see that there is a connect option as you click on the connect option then it will provide you a command that you have to run it on your command prompt.

Image for post
Image for post
Image for post
Image for post

Now we can do the further things that is related to the kubernetes like launching a pods , deployment , exposing the server etc. So before that we need one more command to use the kubernetes from the command line i.e; kubectl so we have to install these command in your system , but in my case i have already installed it.

So now i am going to create a deployment to launch a wordpress server on the top of google cloud. So to create a deployment we need the image name of the wordpress. So before that i want to show that there is no pods & deployment are on my system.

Image for post
Image for post

So to create the deployment we have to use a command i.e;

kubectl create deployment word-press --image=wordpress
Image for post
Image for post

As you can see that we have created a deployment successfully & we can also check that our pods & deployments are successfully launched or not with the help of command i.e;

kubectl get deployments/deploy ( to know about the deployment )kubectl get pods ( to know about the pods )
Image for post
Image for post

so after that we can also check the status or details of nodes that we have launched inside our kubernetes cluster , with the help of command i.e;

kubectl get nodes
Image for post
Image for post

we can also get the other information about the node using the command i.e;

kubectl get nodes -o wide 

We can also increase the number of pods in our deployment with the help of replicas set , because we need the multiple no of pods because of the like our server has received multiple no request from the user then if our single pods is not working fine or might be they exceed their number of users , so at that time if we have multiple pods are running then user must be not face any type of problem while using our site.

So we can increase the no pods with the help of pods with the help of replicas & with command i.e;

kubectl scale deployment word-press --replicas=3
Image for post
Image for post

So here you can see that number pods has been increased and all the pods are running , so we can also know some more information about the pods with the help of command i.e;

kubectl get pods -o wide
Image for post
Image for post

We can also know the service running currently on kubernetes cluster with the help of command i.e;

kubectl get svc/services
Image for post
Image for post

So we want to our server or web server or a site that has been hosted by the outer side of our system s we have to expose our deployments , so when we expose the server then multiple users or clients will reach to our server then we need a load balancer to balance the load ,so we exposed our deployments with the help of command i.e;

kubectl expose deployment word-press --type=LoadBalancer --port=80
Image for post
Image for post

after that we can check the service again it will show the another service has been started.

Image for post
Image for post
Image for post
Image for post

Here you can see that the load balancer has also created on the top of the google cloud , so now you can use this load balancer to expose our IP, so that anyone from public world can use our web server or our website.

→ Step 5: Create a SQL server in the production project and create a database.

Now we have to create the a database server so that we can integrate it with the our wordpress server , so that the data used by the user that can be stored it in our database.

So here we will create a database on gcp cloud , so we use the production project to create the database server. So when we launched or create the database then in a parallel way it will create a MySQL instances.

Image for post
Image for post

As you can see that there is no any SQL instances are present so when we click on the create instance option it will create a SQL instances for us.

Image for post
Image for post

Here you can see that there is three option of database are available , so it is totally depends on you that which type of database server or instances you want to create , here i am choosing MySQL database , i will create a MySQL database or instances.

Image for post
Image for post
Image for post
Image for post

Now you can see that our MySQL server or instance has been created so now we have to do some more changes in our database like we have to set some network settings changes , like we have to allow some users & we have to create a user for our database & then we can use our MySQL instance.

Image for post
Image for post
Image for post
Image for post

As you can see that i have do some changes in my connections i.e; i had allow the IP address , i know it is not good for security purpose , but we are at the stage of testing so we can do it & test our server.

Now we will create a user for our database so that we can use it.

Image for post
Image for post

As you can see that there is a root user which is pre-created user for the MySQL instances but we will create new user for us.

Image for post
Image for post
Image for post
Image for post

As you can see that there is new user has been created with the name ankitkumar , so now we can use the same user for other things.

Now we have done with the one part i.e; create a user , but to store the data we need a database so we have to create a new database for a user so we will do the same.

Image for post
Image for post

These are some pre created or existed database but we will create new database for our use.

Image for post
Image for post
Image for post
Image for post

Now you can see that a new database has been created so now we can use this MySQL instance. We can use the MySQL instance with the help of cloud shell , so we will connect it with the cloud shell.

Image for post
Image for post

As you can see that in the above image we had connect our MySQL instances with the help of cloud shell & we had also shown the database of the instances.

Now we have to launched the wordpress on any of the web browser with the help of load balancer that we had use for the worpress pods , so we can connect it the that ip.

Image for post
Image for post

we have to use this IP & port number to launch the IP .

→ Step 6: Connect the SQL database to the web application launched in the Kubernetes cluster.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

After this stage i have to publish my post or article on the top of wordpress , now i will show my article or post on the wordpress.

Image for post
Image for post

This is all about this article , means how to deploy wordpress as a web server or as a frontend site , how to create a database on the top of GCP cloud , & how to connect both of them .

I hope when you read my article you will kike it , if you will find any type mistakes in my article then you ca contact me .

Thank You so much to read my article.

If you have any queries regarding this article or while performing the task then you can contact to , i will be happy to help you .

Author : Ankit Kumar (Linkedin Profile Link )

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store