Hosting WordPress on GCP K8s Cluster With MySQL Database on AWS- Using Terraform

Mahek Batra
3 min readAug 20, 2021

We are going to deploy a WordPress application on top of Kubernetes cluster using Kubernetes service of Google Cloud Platform (GCP) along with Load Balancer and for database, we will be creating a MySQL db instance using RDS of Amazon Web Services (AWS). All of these using Terraform.

So, these are the steps -

  1. Creating a VPC, subnet and firewall rule inside a project on GCP.
  2. Create a Kubernetes cluster, deploy WordPress on top of it with LoadBalancer service.
  3. Using Relational Database Service (RDS) of AWS and creating a MySQL db instance for connecting it to the WordPress site.

Every resource on GCP needs to be created inside a project, so first we should have a project.

Screenshots of the output:

First we do terraform init to download all the providers used (google, terraform and aws)

terraform init

Now, terraform plan to see what resources will be created actually after apply

terraform plan

Finally, apply to create all the resources.

terraform apply

We can go to GCP console and see all the resourecs are created there (VPC, kubernetes cluster, wordpress deployment, Load balancer)

subnet
vpc
kubernetes cluster
service
service details
workloads

Also, in AWS our MySQL database instance is created

Aws console

Let’s connect to our WordPress site using the load balancer ip address, connect to the database and complete the setup.

This is how we can create a complete WordPress-MySQL architecture using two different cloud platforms.

Github url for the code:

https://github.com/mahekbatra/terraform_task4

--

--

Mahek Batra

BE 3rd year || Information Technology|| Dedicated|| Passionate||