Deploy the Wordpress application on Kubernetes and AWS using terraform

In this article I am gonna explain you that how to deploy the wordpress application on kubernetes and RDS in AWS using terraform.


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

Project Outline:

  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 the 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.


For this project we are using the kubernetes as a provider for creating the cluster.

Create the file with name “” , here u can use any name with extension .tf

provider "kubernetes" {
config_context_cluster = "minikube"}

Deployment of kubernetes on wordpress pod

resource "kubernetes_deployment" "wordpress" {
metadata {
name = "wordpress"}

Creating the replicas of the deployment, here we create 2 replicas

and exposing the cluster on the port 80.

//creating the deployment of cluster with 2 replicasspec {
replicas = 2

selector {
match_labels = {
env = "dev"
region = "IN"
App = "wordpress"


template {
metadata {
labels = {
env = "dev"
region = "IN"
App = "wordpress"
//Exposing the cluster on the port 80spec {
container {
image = "wordpress:4.8-apache"
name = "wordpressdb"

port {
node_port = 32123
port = 80
target_port = 80

type = "NodePort"

We have created the terraform file for kubernetes cluster.

For initialising the terraform resources,

terraform init 

For checking the resources to be deployed use command

terraform plan

For applying

terraform apply --auto-approve

for checking the pods running use

kubectl get pods

For creating the MySQL instance on AWS , we need to write another file for it.

provider "aws" {
region = "ap-south-1"
resource "aws_db_instance" "My_db" {

engine = "mysql"
engine_version = "5.7.30"
instance_class = "db.t2.micro"
allocated_storage = 10
name = "mydb"
username = "wordpress_user"
password = "rootroot"
port = "3306"
publicly_accessible = true
iam_database_authentication_enabled = true
vpc_security_group_ids = ["sg-041bf4230a162e7d0"]
tags = {
Name = "mysql"

For checking the ip address of the wordpress site hosted

minikube ip

Connect to the Ip to get started with it.

That’s all guys, we have successfully created the Wordpress cluster and deployed on the top of Kubernetes with Amazon MySQL database.

I hope it helped you…

Thanks for reading

MLOps| Hybrid Cloud | DevOps | Hadoop | Kubernets | Data Science| AWS | GCP |

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Stack Overflow is a question and answer site for professional and enthusiast programmers.

Chapter 12 -Getting Gui: A Very Graphic Story

This is very promising project. Join fast this project without hesitate.

Continuous Delivery with Maven, Buildkite and packagecloud

Marble diagrams: Indispensable for Rx concepts

What happens when you type gcc main.c ?

Automate your build & release with Github Actions

MongoDB Certified Professional Spotlight: Guru Rajan Ganesan

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
Sriramadasu Prasanth Kumar

Sriramadasu Prasanth Kumar

MLOps| Hybrid Cloud | DevOps | Hadoop | Kubernets | Data Science| AWS | GCP |

More from Medium

[Terraform]: Build Amazon Redis Cache from SNAPShots not are supported. Wait What!!

ACL on S3 bucket objects with Terraform

Automated Static Site Deployment in AWS Using Terraform

VPC👉 IG👉ELB👉RDS using Terraform IAC