AWS TASK-6 Completed successfully

Deploying WordPress on Kubernetes with RDS using Terraform

Aditya Jain

Task Objective

  • Write an Infrastructure as Code using Terraform, which automatically deploys WordPress.
  • For the database use, RDS ( Relational Database Service ) provided by AWS
  • Deploy WordPress as a container either on top of Minikube or EKS or Fargate service on AWS.
  • The WordPress application must be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.


It is a tool that can use the services of any cloud ( also called provider ) with standardized commands. Terraform makes this easier because it is built on a plugin-based architecture. We just have to initialize the plugins of the cloud we want to use. It uses a declarative language called Hashicorp Configuration Language ( HCL ).


Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management. It is an ideal platform for hosting cloud-native applications that require rapid scaling, like real-time data streaming, and many more.

Amazon Relational Database Service (RDS)

It makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching, and backups. Amazon RDS is available on several database instance types — optimized for memory, performance, or I/O.

Database Engines provided RDS :

  • Amazon Aurora
  • PostgreSQL
  • MySQL
  • MariaDB
  • Oracle
  • SQL Server

Now let’s jump right into the solution !!!

Requirements :

  • Minikube
  • kubectl
  • Terraform ( ^0.12.26 )
  • AWS account

Create a deployment using terraform and expose the port of
WordPress using service

To provision anything using Terraform we need their respective providers. Since we have to create a deployment we need a provider called “kubernetes”

config_context_cluster” is an argument wherein we have to specify the path of the config file.

Then run “terraform init” to install the plugin.

The output of “terraform init”

This code will create a deployment with the desired state of 3.

Service is a way using which we can expose an application running on a set of pods as a network service. NodePort is a type of service which exposes the service on each Node’s IP at a static port called “node_port”.

It usually uses selectors in order to monitor/ find the pods in a deployment. This is why selectors play an important role in management.

Now we have to execute “ terraform apply ” to provision our resources.

After its execution, we can verify that all our required resources have been successfully provisioned by the following commands.

By using the obtained endpoint we can access WordPress.

Launch a MySQL database using terraform with the required

Since we have to provision resources in AWS we need a provider called “aws”.

If you have a profile created then specify it in the following way:

I am using the “ default profile.

Then run “terraform init” to install the plugin.

The output of “terraform init”

This will create a DB instance with MySQL. It is important to make this data publicly accessible in order to connect it with WordPress.

Now we have to execute “ terraform apply ” to provision our resources.

Connect the RDS instance with WordPress

We can connect the WordPress application to the RDS database by providing the username, password, database name, and database host.

We can now see that WordPress is connected with the RDS instance.

Kubernetes enables us to easily create multiple pods, then make sure that that number of pods always exists. If a pod does crash it automatically launches new ones with zero downtime. It also has the ability to scale the number of pods and to update or delete multiple pods with a single command.

On the other hand, RDS manages the MySQL database by performing tasks such as hardware provisioning, patching, and backups (automated backup is done which enables point-in-time recovery for any database instance ).

Thanks for Reading !!!!!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aditya Jain

Aditya Jain

Flutter Developer & Full Stack Developer