Deploy the Wordpress application on Kubernetes and SQL on AWS using terraform
😊 Hello Readers, I’m back with another article… In this, I’m going to explain step by step to deploy wordpress application on Kubernetes and SQL on AWS using terraform …
📝 Description :
🔅 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 ,.. Here I’m using Minikube to launch wordpress …
🔅 The Wordpress application should be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.
🎢 Let’s do it step by step …
🔰 Step 1: First, start the minikube VM in your System …
minikube start
🔰 Step 2: Write the code for launching wordpress container on minikube,..
Create this code in ‘A’ folder…
provider "kubernetes" {
config_context_cluster = "minikube"
}
resource "kubernetes_deployment" "wordpress" {
metadata {
name = "rdswp"
}
spec {
replicas = 1
selector {
match_labels = {
env="production"
region="IN"
app="wordpress"
}
match_expressions{
key="env"
operator="In"
values= ["production"]
}
}
template {
metadata {
labels = {
env="production"
region="IN"
app="wordpress"
}
}
spec {
container {
image = "wordpress"
name = "mywp"
}
}
}
}
}
resource "kubernetes_service" "wpservice" {
metadata {
name = "wpservice"
}
spec {
selector = {
app = kubernetes_deployment.wordpress.spec.0.template.0.metadata[0].labels.app
}
port {
node_port = 30321
port = 80
target_port = 80
}
type = "NodePort"
}
}
After writing the code, now initialize the terraform to install kubernetes plugins to connect with minikube VM …
terraform init
👉 Now run the code,..
terraform apply --auto-apporve
👉 Successfully launched wordpress container on minikube … Now Let’s create the RDS database for storing the data of wordpress …
🔰 Step 3: Now write the code to create a database on AWS Cloud,… Here is the code ,…
👉 Note: Create this code in ‘B’ folder …
provider "aws" {
region = "ap-south-1"
profile = "<Ur aws profile name>"
}resource "aws_db_instance" "dbrds" {
identifier = "rdsinstance"
allocated_storage = 15
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t2.micro"
name = "<db name>"
username = "<username>"
password = "<password>"
port = "3306"
iam_database_authentication_enabled = true
publicly_accessible = true
parameter_group_name = "default.mysql5.7"
skip_final_snapshot = true
tags = {
Name = "MySQL_DB"
}
}
👉 Now run the code , before running this code initialize terraform in ‘B’ folder …
terraform initterraform apply --auto-approve
👉 Now the browse the IP of minikube with port number … My IP is 192.168.99.100:30321
👉If you see the above page as run the installation, Finally, we deployed the wordpress container on minikube and SQL Database on AWS using terraform.
That’s all Folks,… See you in the next article …
…. Signing Off ….