Deployment of the WordPress Application on Kubernetes and AWS using Terraform

Shreyas Basutkar
6 min readSep 20, 2020
Task6

Hello World! In this article, I am going to talk about an overview of Terraform. The first thing we should know, What is AWS? What is Terraform? What is the WordPress App? What is Amazon-RDS? What is Kubernetes? How we can deploy the web app on Kubernetes Cluster and store the data using Amazon-RDS for Databases?

So Let’s Start with the theoretical explanations and Practical.

What is AWS?

Amazon Web Services is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis.

Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 175 fully-featured services from data centers globally. Millions of customers — including the fastest-growing startups, largest enterprises, and leading government agencies — are using AWS to lower costs, become more agile, and innovate faster.

What is Terraform?

Terraform is an open-source infrastructure as code software tool created by HashiCorp. Users define and provision data center infrastructure using a declarative configuration language known as HashiCorp Configuration Language, or optionally JSON. Terraform manages external resources with “providers”.

What is the WordPress App?

WordPress is a free and open-source content management system written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as Themes.

What is Amazon-RDS?

Amazon Relational Database Service is a distributed relational database service by Amazon Web Services. It is a web service running “in the cloud” designed to simplify the setup, operation, and scaling of a relational database for use in applications.

What is Kubernetes?

Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation.

How we can deploy the web app on Kubernetes Cluster and store the data using Amazon-RDS for Databases?

There are some following steps for the practice are as follows:

1) As we have to write Infrastructure As A Code using terraform which automatically deploys WordPress Application on Kubernetes Cluster. In my case, I go for local Kubernetes Cluster as Workstation i.e Minikube.

So, let's start to write Infrastructure As A Code using Terraform for the deployment of WordPress Application on Minikube Kubernetes Cluster.

In the above terraform code use of Replica Set which defines with fields, including a selector that specifies how to identify Pods it can acquire, a number of replicas indicating how many Pods it should be maintained, and a pod template specifying the data of new Pods it should create to meet the number of replicas criteria. A ReplicaSet then fulfills its purpose by creating and deleting Pods as needed to reach the desired number. When a ReplicaSet needs to create new Pods, it uses its Pod template.

Use of kubernetes service to acquire the facility of Load Balancer and to expose the deployment of Web Application to public world access. Here I use the service of kubernetes named Node Port which works as a Load Balancer but is not an external Load Balancer like the Elastic Load Balancer in AWS. We can also make the use of ELB for this service.

2) We have to start the Minikube service to perform the practical.

3) Now, we have to run the terraform code. Before running the code we have to first Initialize the code and download the necessary plugins of terraforming for Kubernetes.

terraform init

4) After the terraform init now we can check the code is properly written or are some errors in it by command →

terraform validate

5) After the terraform validate now we run the terraform code which will create Infrastructure As A Code using the command →

terraform apply --auto-approve

6) Now we can see the deployment of WordPress Application is created on the local kubernetes cluster we use named as Minikube.

To see everything in the Kubernetes cluster is properly deployed or not using the command →

kubectl get all

7) As we successfully deployed WordPress Application on kubernetes using Terraform. Now we have to create a back end for WordPress that is the database . It is always critical to managing the database of any web application for that we move towards the use of Database As A Service provided by AWS Cloud called Relational Database Service (RDS).

For WordPress, we are using MySQL RDS by AWS. Now, we have to write another terraform code for MySQL RDS which will create one MySQL database using RDS.

Terraform code for MySQL RDS →

8) Now, again we for the RDS terraform code we have to initialize and apply the terraform code.

terraform init

9) After the terraform init now we can check the code is properly written or are some errors in it by command →

terraform validate
terraform plan
terraform apply --auto-approve

We can see in AWS GUI Console one MySQL database is created in RDS →

10) Finally, now we can launch the WordPress Application using the service URL provided by Node Port of kubernetes cluster. To see the service URL of minikube use the command →

minikube service list

To connect the MySQL database created by RDS to the WordPress Application enter the appropriate details of the database we use for the back end as below →

--

--