Deploy WordPress Application On Kubernetes(Minikube) with AWS RDS Using Terraform

Task Overview:

1. Write an Infrastructure as code using terraform, which automatically deploy the WordPress application

Pre-requisites:

  1. You must have an AWS account and One IAM user WITH Administration power in it . Also you should have User’s Credential file .
  2. AWS CLI , Terraform associated with Command line .
  3. You must Configure Your IAM profile to Command line .
  4. You must have kubectl (client program for Kubernetes cluster) and Minikube configured in your system.
provider "kubernetes" {
config_context_cluster = "minikube"
}
resource "kubernetes_service" "loadbalancer" {
metadata {
name = "loadbalancer"
}
spec {
selector = {
app = "wp"
}
port {
port = 80
target_port = 80
node_port = 32123
}
type = "NodePort"
}
}
resource "kubernetes_deployment" "wp-deploy" {
metadata {
name = "wp-deploy-aman"
}
spec {
replicas = 1
selector {
match_labels = {
app = "wp"
}
}
template {
metadata {
labels = {
app = "wp"
}
}
spec {
container {
image = "wordpress:4.8-apache"
name = "wp-con"
}
}
}
}
}
terraform init
terraform validate 
terraform plan
terraform apply --auto-approve
kubectl get all
provider "aws" {
region = "ap-south-1"
profile = "aman"
}
resource "aws_db_instance" "mysql-db" {
allocated_storage = 20
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t2.micro"
vpc_security_group_ids = [aws_security_group.sg.id]
identifier = "mysqldb"
name = "mysqldb"
username = "aman"
password = "Amaner123"
parameter_group_name = "default.mysql5.7"
publicly_accessible = true
skip_final_snapshot = true
}data "http" "myip"{
url = "http://ipv4.icanhazip.com"
}resource "aws_security_group" "sg" {
name = "mysql-sg"ingress {
description = "only 3306 port for MySQL"
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.body)}/32"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "mysql-sg"
}
}output "dns"{
value = aws_db_instance.mysql-db.address
}
terraform init
terraform validate 
terraform plan
terraform apply --auto-approve
kubectl delete all --all
terraform destroy --auto-approve

#aws #righteducation #rds #keeplearningkeepsharing