Deploying WordPress on Google Cloud GKE and Cloud SQL

Deploying WordPress on Google Cloud GKE and Cloud SQL


This article describes us how to launch WordPress website on Google Kubernetes Engine and connect it to Cloud SQL service for database when both of them are in different projects connected via VPC peering( a great feature of Google Cloud ).

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

Firstly, Why 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 the platform.

Google tries to keep the backend as simple as possible and uses a simple file system. This system is the foundation of the Google cloud platform. It handles requests for information via basic commands like write, read, and open. It is a distributed system of computing. Learn more from the link below:

Virtual Private Network (VPC) :

"A Virtual Private Cloud (VPC) is a global private isolated virtual network partition that provides managed networking functionality for your Google Cloud Platform (GCP) resources."(from Google docs) It provides multiple features and functionality making it easy for us to work on networking from console.

Cloud SQL :

Google Cloud's offering for fully managed relational database service for MySQL, PostgreSQL, and SQL Server. Its much easy to manage, scale, backup, copy and import or export data directly from their managed services without us to think about how its working,

Google Kubernetes Engine (GKE) :

GKE is Google Cloud's one step solution for providing secured and managed Kubernetes service with four-way auto scaling and multi-cluster support. Using GKE is much easy and simple. It deploys Docker containers for on top of the cluster.


For this task, Google Cloud SDK should be installed and configured along with Kubectl for managing GKE.

STEP 1: Create an account and create two projects developer and production. This can be don by clicking on New Project button.

No alt text provided for this image

STEP 2: Create a new VPC from both the projects. Go to VPC Network option under networking and then click on Create VPC Network. For this specify the names and CIDR for the subnet. For this refer to the images :

No alt text provided for this image
No alt text provided for this image

Add the firewall rules to enable all the ports you want. Finally the VPC will get created.

No alt text provided for this image

Repeat the same steps for both the projects.

STEP 3: Now since these two are separate projects, they lack connectivity and we need to create a VPC peering to enable this for this we again go to VPC Network and select VPC Networking Peering under it. From there using the project ID connect to the another project and connect the two VPC created in last step.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

STEP 4: For creating a Kubernetes Cluster we go to Kubernetes Engine under Compute and go to Cluster. Create a cluster in multiple regions of the zone and make it

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Next, we need to configure kubectl on our system with the cluster created. For this we click on connect and run the command provided on the configured Cloud SDK on our system. This will allow us to use the Kubernetes cluster running on the Google Cloud directly from our system.

No alt text provided for this image

Now we launch a WordPress container on top of the cluster, scale it and then expose it through a load balancer to balance the load.

kubectl create deployment  wpapp --image=wordpress

kubectl scale deployment wpapp --replicas=3

kubectl expose deployment wpapp --type=LoadBalancer  --port=80

Then we can check the status of all the services using the command

kubectl get all

No alt text provided for this image

Now after some time the LoadBalancer IP comes up and we can connect to the WordPress Docker Container using the IP.

No alt text provided for this image
No alt text provided for this image

STEP 5: We need a SQL server to connect to the WordPress for it to be able to save the data. For this we create a Cloud SQL instance in the production project. Go to SQL under Databases.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Select MySQL and add details like name and password. Also enable connectivity from all Public IPs and Private IPs so that it gets connected internally using private IP from Google's internal network using VPC Pairing.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Finally in a few minutes the SQL instance will come up.

No alt text provided for this image

Now lets create a Database inside this instance. For this from inside the SQL instance page go to databases and click on create database and give a name of to it and create it. This Database will be used by WordPress to store the data.

No alt text provided for this image

STEP 6: Now we need to connect the WordPress application to the MySQL Database. For this we ahead with the configuration of WordPress. Then using the credentials and database name we connect to the database.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Finally we have connected the cloud SQL with WordPress.

After this its time to completely destroy the Projects so that we are not charged for running the infrastructure in the background. For this click on manage resource icon near New Project button.

No alt text provided for this image

Then, select delete the project by clicking on the button for each project.

No alt text provided for this image
No alt text provided for this image

This clears all the infrastructure created by us and we are now ready to go.

要查看或添加评论,请登录

Vikash Kumar的更多文章

社区洞察

其他会员也浏览了