RDS CONNECTED WITH WORDPRESS WHICH IS RUNNING ON MINIKUBE

 


Task-6 


Deploy the Wordpress application on Kubernetes and AWS using terraform including the following steps;


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.


AWS — Amazon Web services is a Public Cloud that provides IaaS, PaaS, and SaaS.


TERRAFORM — Terraform is created by HashiCorp.It is an open-source infrastructure as a code service. It has its own language known as HashiCorp Configuration Language. Terraform is used to make an application that is integrated with multiple clouds(like AWS, Azure, Openstack, etc).

It provides Standardisation.

Terraform file extension is “file_name.tf”.



MINIKUBE -

Minikube is an open-source tool that helps to run Kubernetes on a local computer.

Before using minikube we need to start it so here I wrote terraform code to start minikube on my Local Computer.


resource "null_resource" "minikubestart" {

  provisioner "local-exec" {

    command = "minikube start"

    

  }

}


KUBERNETES PROVIDER-

Here k8s provider is provided which uses minikube.


provider "kubernetes" {

  config_context_cluster = "minikube" 

}

 


KUBERNETES DEPLOYMENT-


resource "kubernetes_deployment" "deploynode" {

  metadata {

    name = "wordpress-node"

    labels = {

      test = "cms"

    }

  }

 

  spec {

    replicas = 2

 

    selector {

      match_labels = {

        test = "cms"

      }

    }

 

    template {

      metadata {

        labels = {

          test = "cms"

        }

      }

 

      spec {

        container {

          image = "wordpress"

          name  = "wordpress-sql"

 

        }

      }

    }

  }

}


KUBERNETES SERVICE-


resource "kubernetes_service" "servicenode" {

  metadata {

    name = "service-node"

  }

  spec {

    selector = {

      test = "${kubernetes_deployment.deploynode.metadata.0.labels.test}"

    }

    port {

      port        = 80

      target_port = 80

      protocol = "TCP"

    }

 

    type = "NodePort"

  }

   depends_on = [kubernetes_deployment.deploynode]

}

 


AWS PROVIDER-


provider "aws" {

  region                  = "ap-south-1"

  profile                 = "mymanali"

}


RDS -

Relational Database Services is a relational cloud-based database.


resource "aws_db_instance" "mydb" {

  allocated_storage    = 20

  storage_type         = "gp2"

  engine               = "mysql"

  engine_version       = "5.7"

  instance_class       = "db.t2.micro"

  name                 = "mysqldb"

  username             = "manali"

  password             = "123456789"

  parameter_group_name = "default.mysql5.7"

  skip_final_snapshot  = true

  publicly_accessible = true

}


MINIKUBE SERVICE LIST-

It will provide the IP to connect to Wordpress.

resource "null_resource" "minikubeservice" {

  provisioner "local-exec" {

    command = "minikube service list"

    

  }

  depends_on = [

      kubernetes_deployment.deploynode,

      kubernetes_service.servicenode,

      aws_db_instance.mydb

      ]

}


RDS is created.



WORDPRESS is opened by the IP.





TERRAFORM COMMANDS -

terraform init” -> install the required plugins and initialize the terraform.

terraform apply” -> run the program

terraform destroy” -> delete all the things that are running.

terraform apply --auto-approve” -> run the program without asking yes/no.

terraform destroy --auto-approve” -> delete all the things that are running without asking yes/no.


COMMANDS -

  1. This command will download the required plugins.



  1. This command will apply all the changes.


  1. This is the resource I used in code to see the IP.


  1. “kubectl get deploy” command will show the deployed image.


  1. “kubectl get rs” command will show the replica sets running.


  1. “kubectl get services” command will show the service.


  1. “kubectl get pods” command will show the pods.



  1. This command will delete everything in just one click.


GITHUB URL - https://github.com/manali1230/Minikube-RDS.git


Comments

Popular posts from this blog

HOW GOOGLE USES MACHINE LEARNING ??

AWS CLOUDFRONT SETUP

Terraform Replica Set Code