Deploying the WordPress application on Kubernetes and AWS using Terraform and RDS

Deepanshu Chajgotra
4 min readOct 13, 2020

--

Amazon RDS

Amazon RDS is the Relational Database Service offered as a web service by Amazon. It makes it easy to set-up and operate a relational database in the cloud. It provides a very cost-effective way to use industry’s leading RDBMS software as a managed service.

Instead of concentrating on database features, you can concentrate more on the application to provide high availability, security, and compatibility. RDS is a fully managed RDBMS service.

Now that we understand what is Amazon RDS and what are its benefits, let’s move on about various Database engines that RDS offers.

Task Overview:-

Deploy the Wordpress application on Kubernetes and AWS using terraform including the following steps;

  • Write an Infrastructure as code using terraform, which automatically deploy the Wordpress application
  • On AWS, use RDS service for the relational database for Wordpress application.
  • Deploy the Wordpress as a container either on top of Minikube or EKS or Fargate service on AWS
  • The Wordpress application should be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.

Try each step first manually and write Terraform code for the same to have a proper understanding of workflow of task.

Task Description:-

To deploy wordpress on the top of minikube, first we have to start minikube

Step 1:- Terraform code to deploy the Wordpress application on top of Minikube and exposing to outside world using NodePort.

provider "kubernetes" {
config_context_cluster = "minikube"
}
resource "kubernetes_service" "wplb" {
metadata {
name = "mywplb"
}
spec {
selector = {
app = "wordpress"
}
session_affinity = "ClientIP"
port {
port = 80
target_port = 80
node_port = 30201
}
type = "NodePort"
}
}
resource "kubernetes_deployment" "deployment" {
metadata {
name = "mywp"
}
spec {
replicas = 3
selector {
match_labels = {
app = "wordpress"
}
}
template {
metadata {
labels = {
app = "wordpress"
}
}
spec {
container {
image = "wordpress:4.8-apache"
name = "mywp"
}
}
}
}
}

Step 2:- Terraform code to create a MySQL database using AWS RDS.

provider "aws" {
region = "ap-south-1"
profile = "deepanshu"
}
resource "aws_db_instance" "mydb" {
allocated_storage = 10
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7.30"
identifier = "deep-database"
instance_class = "db.t2.micro"
name = "Deep2612"
username = "admin"
password = "hello*123#"
port = "3306"
parameter_group_name = "default.mysql5.7"
iam_database_authentication_enabled = true
publicly_accessible = true
skip_final_snapshot = true
}

Before running this code in order to build complete infrastructure, we to run this command . It will download all the required plugins .

terraform init

Once done run the below command to start creating the above structure:

terraform apply -auto-approve

Wordpress and MySQL is successfully launched. After that run

minikube service list

This will give the public IP where WordPress is running ongoing to that IP we get below page. Finally,our WordPress server is successfully deployed on the top of Kubernetes:-

For destroying the entire Infrastructure use the command

terraform destroy --auto-approve

Thank You!!!

--

--