Deploy the WordPress Application on Kubernetes and AWS using terraform
Problem Statement :
1. Write an Infrastructure as code using Terraform, which automatically deploy the WordPress application
2. On AWS, use RDS service for the relational database for WordPress application.
3. Deploy WordPress as a container either on top of Minikube or EKS or Fargate service on AWS
4. The WordPress application should be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.
Solution:
What is Terraform?
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.
The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.

What is WordPress?
WordPress is a web publishing software you can use to create your own website or blog. Since it was released in 2003, WordPress has become one of the most popular web publishing platforms. And today it powers more 35% of the entire web — everything from hobby blogs to some of the most popular websites online.
WordPress enables you to build and manage your own full-featured website using just your web browser — without having to learn how to code. In fact, if you’ve ever used a text editor like Microsoft Word, you’ll be right at home with the WordPress Editor.
What Is Amazon Relational Database Service (Amazon RDS)?
Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the AWS Cloud. It provides cost-efficient, resizable capacity for an industry-standard relational database and manages common database administration tasks.

DB Instances
The basic building block of Amazon RDS is the DB instance. A DB instance is an isolated database environment in the AWS Cloud. Your DB instance can contain multiple user-created databases. You can access your DB instance by using the same tools and applications that you use with a standalone database instance. You can create and modify a DB instance by using the AWS Command Line Interface, the Amazon RDS API, or the AWS Management Console.
Minikube
Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop for users looking to try out Kubernetes or develop with it day-to-day.
Minikube Features
Minikube supports the following Kubernetes features:
- DNS
- NodePorts
- ConfigMaps and Secrets
- Dashboards
- Container Runtime: Docker, CRI-O, and containerd
- Enabling CNI (Container Network Interface)
- Ingress
First configure AWS from Command line
Open command line
aws configure

Now create a Repository in Desktop for Task 6 and create Notepad File for Kubernetes and for AWS provider

In Wordpress.tf
provider "kubernetes" {
config_context_cluster = "minikube"
}
resource "kubernetes_deployment" "wordpress" {
metadata {
name = "wordp"
}
spec {
replicas = 2
selector {
match_labels = {
env = "development"
region = "IN"
App = "wordpress"
}
match_expressions {
key = "env"
operator = "In"
values = ["development" , "webserver"]
}
}
template {
metadata {
labels = {
env = "development"
region = "IN"
App = "wordpress"
}
}
spec {
container {
image = "wordpress:4.8-apache"
name = "wordpressdb"
}
}
}
}
}
resource "kubernetes_service" "wordpresslb" {
metadata {
name = "wplb"
}
spec {
selector = {
app = "wordpress"
}
port {
node_port = 32145
port = 80
target_port = 80
}
type = "NodePort"
}
}
In Mysql.tf
provider "aws" {
region = "ap-south-1"
profile = "mytask6"
}
resource "aws_db_instance" "MySQL" {
allocated_storage = 20
engine = "mysql"
engine_version = "5.7.30"
instance_class = "db.t2.micro"
name = "mydb"
username = "mydatebase"
password = "redhat12345"
port = "3306"
publicly_accessible = true
skip_final_snapshot = true
iam_database_authentication_enabled = true
vpc_security_group_ids = ["sg-896e29eb"]
tags = {
Name = "mysql"
}
}
Now initialize the Terraform code and then validate the code

Run Minikube to Deploy WordPress init

terraform plan



Now Launch terraform everything looks perfect after checking the code
terraform apply --auto-approve

now check full minikube by using
kubectl get all

now check minikube IP

now check minikube all service list

Now Open Chrome and paste the URL in the Browser or type this command and press Enter
chrome http://192.168.99.119:32145
After putting this command chrome will open with WordPress site
now configure the admin page and launch the site by filling user name and password and DNS name.


AWS RDS services output screenshot


TASK COMPLETED
now destroy all
terraform destroy --auto-approve
THANKS FOR READING MY ARTICLE !!!