Getting started with GCP: Launching WordPress with SQL backend on Kubernetes Cluster.

Ankush Sinha Roy
7 min readSep 8, 2020

--

You might like to consider reading my previous articles if you are a complete beginner to this cloud computing world:

  1. 10 reasons to upgrade to Cloud for your business. Also, which one to choose?
  2. Start building on Google Cloud Platfom(GCP) with $300 free and a Cheatsheet to help you get started.

Let’s consider the problem statements we will be working on before moving forward.

  1. We have to create two different projects such as Dev and Prod.
  2. In Dev project, we have to create one VPC in the California region for the Prod project we have to create one VPC in the Singapore region for Dev project.
  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, Drupal, etc pod as a front-end on the top of GKE Cluster and link it with SQL database which is acting as a back-end for us.
Overview!

Let’s get started!

In my previous article, I talked about why Projects are so important in GCP. So, let’s make some new projects inside which we can launch our own services.

New Project!

Both the projects: project-dev and project-production having project IDs project-dev-288720 and project-production-288720 respectively, have been created!

Next, we have to enable their billing for these 2 projects, if not already enabled, in order to start building.

Now, we have to create a Virtual Private cloud (VPC). For that, we need to enable API and Services.

ENABLE APIS AND SERVICES

Select the Compute Engine API and ENABLE it.

Enabled!
VPC Networks

Select VPC networks

Click on CREATE VPC NETWORK

Here, we will create a custom VPC Network, myprodvpc in us-west1 having a subnet: subnet-lab1.

IP address range: 10.0.20.0/24

CREATE!

Thus, VPC: myprodvpc for the production environment is created.

Now, we need to repeat the same process of enabling the Compute Engine API and creating a VPC for the developer environment, project-dev.

mydevvpc

Here, mydevvpc is created in the region asia-southeast1 having IP adress range: 10.0.10.0/24 .

Now, VPC Network Peering.

project-production:

Name: vpc-prod-peer

Just click on create after giving the displayed details.

As we can see, vpc-prod-peer has been created, but it is Inactive.
Now, we have to create a second peering in the dev environment for the peering to become active.

project-dev:

We will have to create a peering connection in project-dev just like we did for project-production.

Now, as soon as we click on CREATE, we will see an active VPC network peering connection is created in both the projects!

vpc-dev-peer
vpc-prod-peer

Now, Let’s move on to Google Kubernetes Engine!
We will be launching a Kubernetes cluster using the K8s service provided by GCP.

Google Kubernetes Engine

The Kubernetes Engine API will be enabled automatically within a matter of seconds and once enabled, we will be able to create our K8s cluster.

I have selected the sia-southeast1 region: the same region where the project-dev has been created. Now, follow these specifications to launch your Kubernetes Cluster!

After the specifications are provided, click on CREATE!

As we can see, within sometime, our kubernetes cluster: dev-cluster has been successfully configured! These are the 3 instances launched:

Now, we will have to Connect the K8s cluster and select the Run in Cloud Shell option.

Command for connecting to the cluster

We use kubectl get nodes to see the nodes that we have created. But when we use kubectl get pods , we see that there are no pods available.

Thus, to deploy WordPress on the top of the kuberenetes cluster we’ve created use kubectl create deployment wordpress-pod --image=wordpress:5.1.1-php7.3-apache . It will create a deployment named wordpress-pod.
Use kubectl get all to get the IP of the pod.

Now, we have to expose this deployment IP using a K8s Loadbalancer service at port no 80. Command: kubectl expose deployment wordpress-pod --type=LoadBalancer --port=80

LoadBalancer External-IP

Now, we can see that a Load balancing service has been created and by using the kubectl get svc command, we can get the external IP.

Thus, the external IP can be used from anywhere in the world to launch WordPress.

Now, before we click on Let’s go, we need to create a database to get started! We will create the database in the project-production i.e. in US region.

Cloud SQL Database in project-production
Configuring the SQL database
mysql-db created!

We are allowing all networks access to this database.

Next we have to create a new user with an username and password.

Next, create a new database.

New database created!

Click on option “connect using cloud shell”, it will active cloud shell from where we can connect with SQL database using the root user.

We can see that our database is displayed here. Here, I used the root user, but we can test the same using the user we created, because both have the same power and access.

We will use the public IP of the Database in WordPress.

Give the required details according to the username and password given.

Installation successful!

Thus, we can start publishing on our freshly created WordPress website.

You can contact me for any further doubts!

Let’s connect on LinkedIn

Thank you for reading!

--

--