Deploy the Wordpress application on Kubernetes and AWS using terraform and RDS Task 6

Deploy the Wordpress application on Kubernetes and AWS using terraform and RDS Task 6

What is Kubernetes?

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services. On K8S (short for Kubernetes) we create containers and launch our application on top of these containers. Containers provide isolation and everything is managed by K8S.

What are Containers?

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

What is the need of Kubernetes?

Containers are a good way to bundle and run your applications. In a production environment, you need to manage the containers that run the applications and ensure that there is no downtime. For example, if a container goes down, another container needs to start. This is where Kubernetes helps us. Everything is managed by Kubernetes itself. We just need to specify the templates of the container and Kubernetes will do its job.

What is AWS-RDS?

Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and re-sizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching and backups.

Prerequisite:

What is the Task?

In this task we will deploy the WordPress application on top of Kubernetes which will be connected to the AWS-RDS database where it will store all the critical information. We will create this infrastructure using Terraform. Steps to the task include the following:

  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.

How to Accomplish this Task?

Follow the steps below to accomplish the task:

Step 1 : Log in to AWS using the CLI. Also we need to start our Minikube VM.

No alt text provided for this image
No alt text provided for this image

Step 2 : In our code we need to initialize the provider that we want to use in our code. So we need to initialized Kubernetes and AWS.

provider "aws"{
    region = "ap-south-1"
    shared_credentials_file = "C:/Users/admin/Downloads/new_user_credentials"
    profile = "harsh"

}



provider "kubernetes" {
    config_context_cluster = "minikube"

}


In our CMD we need to run the Terraform init command.

No alt text provided for this image

Step 3 : Now we need to write the code for deploying Wordpress on Minikube. We will also be creating a Load Balancer service on Kubernetes which will expose our deployment.

resource "kubernetes_deployment" "wpdeployement" {
    metadata {
        name = "wordpress-deployment"
        labels = {
            type = "frontend_deployment"
        }
    }


    spec {
        replicas = 1
        
        strategy {
            type = "RollingUpdate"
        }


        selector{
            match_labels = {
                type = "cms"
                env = "prod"
            }
        }


        template {
            metadata {
                labels = {
                    type = "cms"
                    env = "prod"
                }
            }


            spec {
                container {
                  image = "wordpress"
                  name = "wordpress"
                  port {
                    container_port = 80
                  }
                }
            }
        }
    }
}


resource "kubernetes_service" "loadbalancer" {
    depends_on = [kubernetes_deployment.wpdeployement]
    metadata {
        name = "wordpress-service"
    }


    spec {
        type = "NodePort"
        selector = {
          type = "cms"
        }
        port {
            port = 80
            target_port = 80
            protocol = "TCP"
        }
    }

}


Step 4 : Now we need to create our Database where the WordPress application will store all its data. For this we are using AWS-RDS.

resource "aws_db_instance" "wpdb" {
  allocated_storage    = 20
  storage_type         = "gp2"
  engine               = "mysql"
  engine_version       = "5.7"
  instance_class       = "db.t2.micro"
  name                 = "RDS"
  username             = "vinod"
  password             = "wordsqlpass"
  skip_final_snapshot = true
  publicly_accessible = true
  port = 3306

}

Step 5 : Next step is to run the infrastructure using the Terraform apply command.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 6 : After the infrastructure is created now we need to visit the WordPress website.Next we have to fill all the information of the database and after clicking the next button everything will be installed and configured.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Thus now we have accomplished the task of automating the deployment of WordPress on top of Kubernetes with Database in AWS using Terraform.

Thank You!!!






要查看或添加评论,请登录

Harsh Rajotya的更多文章

  • Task 1 AWS CLI(Command Line Interface)

    Task 1 AWS CLI(Command Line Interface)

    Hello Everyone !!! Today’s my Article is on AWS CLI In this task we have to Create a Key pair. Create a Security group.

    4 条评论
  • AWS: Netflix Case Study

    AWS: Netflix Case Study

    What is Cloud Computing? Cloud computing is the practice of delivering resources including tools and applications like…

  • Task-4(Hybrid Multi Cloud Computing)

    Task-4(Hybrid Multi Cloud Computing)

    In this task perform task-3 with an additional feature to be added that is NAT Gateway to provide the internet access…

  • Task 3- Create a vpc Infrastructure and Host a wordpress Application with Mysql

    Task 3- Create a vpc Infrastructure and Host a wordpress Application with Mysql

    Finally completed!!! . In this task we have to create a web portal for our company with all security as much as…

  • Automate AWS cloud using TERRAFORM

    Automate AWS cloud using TERRAFORM

    TASK 2 Description Create Security group which allow the port 80. Launch EC2 instance.

  • AWS-EKS

    AWS-EKS

    ELASTIC KUBERNETES SERVICE: Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service…

  • task 1

    task 1

    What is Cloud Computing? Cloud computing is the on-demand availability of computer system resources, especially data…

社区洞察

其他会员也浏览了