Deployment of Web Application On Local Kubernetes Cluster by Integrating with AWS RDS using Terraform.

What is kubernetes?

Task Begins:

resource "null_resource" "minikubestart" {
provisioner "local-exec" {
command = "minikube start"
}
}
provider "kubernetes" {
config_context_cluster = "minikube"
}
resource "kubernetes_deployment" "wordpress" {
metadata {
name = "wp"
}
spec {
replicas = 3
selector {
match_labels = {
env = "production"
region = "IN"
App = "wordpress"
}
match_expressions {
key = "env"
operator = "In"
values = ["production" , "webserver"]
}
}
template {
metadata {
labels = {
env = "production"
region = "IN"
App = "wordpress"
}
}
spec {
container {
image = "wordpress:4.8-apache"
name = "wp"
}
}
}
}
}
resource "kubernetes_service" "wordpresslb" {
metadata {
name = "wplb"
}
spec {
selector = {
app = "wordpress"
}
port {
protocol = "TCP"
port = 80
target_port = 80
}
type = "NodePort"
}
}

Another file for creating the RDS on top of AWS.

provider "aws" {
region = "ap-south-1"
profile = "testing"
}
resource "aws_db_instance" "mydb" {
allocated_storage = 20
identifier = "dbinstance"
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7.30"
instance_class = "db.t2.micro"
name = "mydb"
username = "abhishek"
password = "abhi858585"
iam_database_authentication_enabled = true
parameter_group_name = "default.mysql5.7"
skip_final_snapshot = true
publicly_accessible = true
tags = {
Name = "sqldb"
}
}

Next file is for providing the IP to connect to Wordpress:

resource "null_resource" "minikubeservice" {
provisioner "local-exec" {
command = "minikube service list"

}
depends_on = [
kubernetes_deployment.wordpress,
kubernetes_service.wordpresslb,
aws_db_instance.mydb
]
}

Then,

Now for checking our plan:

kubectl get all

Thank You…….

--

--

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