AWS TASK-6 Completed successfully

Deploying WordPress on Kubernetes with RDS using Terraform

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.

Terraform

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

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.

  • PostgreSQL
  • MySQL
  • MariaDB
  • Oracle
  • SQL Server

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

Requirements :

  • kubectl
  • Terraform ( ^0.12.26 )
  • AWS account
provider "kubernetes" {
config_context_cluster = "minikube"
}
resource "kubernetes_deployment" "wordpressdp" {
metadata {
name = "wordpress"
}

spec {
replicas = 3

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

}

template {
metadata {
labels = {
env = "dev"
region = "IN"
App = "wordpress"
}
} spec {
container {
image = "wordpress:4.8-apache"
name = "mywp"
}
}
}
}
}
resource "kubernetes_service" "wplb" {
metadata {
name = "wordpress"
}
spec {
selector = {
App = "wordpress"
}

port {
node_port = 30300
port = 80
target_port = 80
}

type = "NodePort"
}
}
provider "aws"{
region = "ap-southeast-1"
}
provider "aws" {
region = "ap-southeast-1"
profile = "profile_name"
}
resource "aws_db_instance" "mysqldb" {
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t2.micro"
allocated_storage = 10
storage_type = "gp2"
name = "prodDB"
username = "aditya"
password = "adityaj"
port = "3306"
publicly_accessible = true
skip_final_snapshot = trueparameter_group_name = "default.mysql5.7"

tags = {
Name = "prodDB"
}
}

Thanks for Reading !!!!!

Flutter Developer