Deploying WordPress on GCP using Kubernetes Engine

Pranav Chaturvedi
6 min readOct 9, 2020

--

Hello everyone, In this article, I will show how to deploy WordPress on GCP using Kubernetes Engine.

What is Google Cloud Platform?

Google Cloud Platform (GCP), offered by Google, is a suite of cloud computing services that run on the same infrastructure that Google uses internally for its end-user products, such as Google Search, Gmail, file storage, and YouTube. Alongside a set of management tools, it provides a series of modular cloud services including computing, data storage, data analytics, and machine learning.

Task Description :

  1. We have to create two different projects such as Dev and Prod.
  2. In the Dev project, we have to create one VPC in the asia-northeast1 region while in the Prod project we have to create one VPC in asia-southeast1 region.
  3. We have to connect both the VPC using VPC Peering.
  4. In the Dev project: We have to launch a Kubernetes Cluster using GCP Google Kubernetes Engine Service.
  5. In the Prod project: We have to create MySQL Database using GCP SQL service.
  6. We have to launch WordPress pod as a front-end on the top of GKE Cluster and link it with the MySQL database which is acting as a back-end for us.

Step 1: As we are using Qwiklabs for this task, In qwiklabs we are already given a pre-created project to work upon, So we will directly jump to VPC Networks namely dev and prod

As you can see in the above image, I have created two VPC Networks dev and prod in asia-northeast1 and asia-southeast1 regions respectively.

Step 2: Create the VPC peering for both the network.

Go to VPC network peering -> create a connection. Create VPC peering for dev project. After you create the VPC peering for dev project, Initially it will show in Inactive mode, that’s because the peering connection will be established only when, if the other projects has also one VPC peering then the status will be active.

So in a similar way, we will create a VPC peering for the prod project also so that we can establish the connection between both the network. In the below image, you can see VPC peering for both projects has been created and is active.

Step 3:- Now download and install Google Cloud SDK and Open it

We can download the CLI version of GCP from the given link: https://cloud.google.com/sdk/docs/quickstart-windows

After installing, open the CLI version and enter the command to do the initial setup of Google cloud and to create new or reinitialize Google cloud configurations.

gcloud init

As you can see, I have successfully logged into our account from Cloud SDK/CLI.

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

As we had already mentioned that we have to deploy a web server on the top of GCP, so to do this task we have to use the GKE service.

We can host the server through pods only & 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 top of GCP.

As you can see, I have successfully created a Kubernetes cluster named “cluster1”. I have also done some customizations like,

  1. specify the location type as “Regional” and also choose the region same as one of the above created VPC networks. I have chosen as asia-southeas1
  2. Changed number of nodes to launch per region to 1
  3. Choose series as N1 in the Nodes section.
  4. In the Networking section choose network as “dev” and subnet as “devproject”

Step 5 — Install the Kubectl command on GCP CLI and connect it to the cluster.

Now to create the deployment to launch a WordPress server on top of GCP. we use the command.

kubectl create deployment word-press — image=wordpress

Now to scale the pods, we use the command

kubectl scale deployment word-press — replicas=3

Now we will expose the 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.

kubectl expose deployment word-press — type=LoadBalancer — port=80

After running above the command, Go to load balancing in the Network Services and you will see load balancer has been created.

Step 6: Create MySQL Database using GCP SQL service in the production project.

Now we have to create a database server so that we can integrate it with our WordPress server so that the data used by the user that can be stored in our database. We will use the production project to create a database server. So when we launched or create the database then in a parallel way it will create MySQL instances.

Go to SQL -> Instances -> Create cloud SQL instances. Choose the MySQL option from the given 3 SQL Database options.

After creating a MySQL instance. Go to connections and choose Public IP.

Now click on the user's section and create one user

Now click on Databases and create one database. I have created with the name “wordpress”.

Step 7: We have to launch WordPress pod as a front-end on the top of GKE Cluster and link it with the MySQL database which is acting as a back-end for us.

Now we have to launch the WordPress on any of the web browsers with the help of a load balancer that we had used for the WordPress pods, so we can connect it to that IP.

Now give the site title, username, password, and Email ID and click on install WordPress.

After logging in successfully, You will see the sample WordPress site.

Task completed successfully. Thank you for your time. :)

--

--