Deploy the  WordPress Application on Kubernetes and RDS services of AWS using Terraform

Deploy the WordPress Application on Kubernetes and RDS services of AWS using Terraform

Amazon Relational Database Service (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 resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching and backups. It frees you to focus on your applications so you can give them the fast performance, high availability, security and compatibility they need.

Description of the task:

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.

Solution:

1. Create a Provider.

provider "aws"{
  region = "ap-south-1"
  profile= "myawsprofile"
}

2. Create VPC and Subnet.

data "aws_vpc" "default" {
  default= true
}
 
data "aws_subnet_ids" "all" {
vpc_id= data.aws_vpc.default.id
}

3.Create RDS service on AWS.

module "db" {
  source  = "terraform-aws-modules/rds/aws"
  version = "~> 2.0"


  identifier = "db1"


  engine            = "mysql"
  engine_version    = "5.7.19"
  instance_class    = "db.t2.micro"
  allocated_storage = 10
  storage_type      ="gp2"
  storage_encrypted = false


  username = "Demon"
  password = "ritikgupta"
  port     = "3306"


  iam_database_authentication_enabled = false


 
  subnet_ids = data.aws_subnet_ids.all.ids
  publicly_accessible= true


  availability_zone ="ap-south-1a"


  maintenance_window = "Mon:00:00-Mon:03:00"
  backup_window      = "03:00-06:00"






  tags = {
    Owner       = "user"
    Environment = "dev"
  }


  # DB parameter group
  family = "mysql5.7"


  # DB option group
  major_engine_version = "5.7"


  # Snapshot name upon DB deletion
  final_snapshot_identifier = "demodb"


  # Database Deletion Protection
  deletion_protection = false


  multi_az = false
  backup_retention_period=0
  enabled_cloudwatch_logs_exports=["audit","general"]
  
  parameters = [
    {
      name = "character_set_client"
      value = "utf8"
    },
    {
      name = "character_set_server"
      value = "utf8"
    }
  ]


  options = [
    {
      option_name = "MARIADB_AUDIT_PLUGIN"


      option_settings = [
        {
          name  = "SERVER_AUDIT_EVENTS"
          value = "CONNECT"
        },
        {
          name  = "SERVER_AUDIT_FILE_ROTATIONS"
          value = "37"
        },
      ]
    },
  ]
}

4.Create kubernetes deployment which deploys WordPress over minkube.

provider "kubernetes" {
  config_context_cluster = "minikube"
}


resource "kubernetes_deployment""wordpress" {
  metadata {
    name = "mywp"
  }


  spec {
    replicas = 2


    selector {
      match_labels = {
        env="production"
        region="IN" 
        app="wordpress"
      }
       match_expressions{
        key="env"
        operator="In"
        values= ["production"]
         }
    }


    template {
      metadata {
        labels = {
        env="production"
        region="IN" 
        app="wordpress"
        }
      }


      spec {
        container {
          image = "wordpress"
          name  = "mywp"
        }
      }
    }
  }
}


resource "kubernetes_service" "wordpress" {
  metadata {
    name = "mywp"
  }
  spec {
    selector = {
      app = kubernetes_deployment.wordpress.spec.0.template.0.metadata[0].labels.app
    }


    
    port {
      node_port = 30321
      port        = 80
      target_port = 80
    }


    type = "NodePort"
  }
}

5. Now, we use the following command to start the minikube.

minkube start

6.Now, our terraform code is complete. So, we have to initialize and launch the infrastructure by using following commands:

terraform init

terraform validate

terraform apply
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

7. Now we go to the AWS console and check the database launched in RDS service.

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

8. we can check the pods launched over kubernetes by using following command :

kubectl get all
No alt text provided for this image

9.By using the provided URL, we can launch the WordPress Server.

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

10.At the end, to delete the whole infrastructure we use the following command:

terraform destroy
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Thanks for the reading!!


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

Rittik Gupta的更多文章

  • Neural Network and its use case

    Neural Network and its use case

    Neural Network: A neural network is a system designed to act like a human brain. It’s pretty simple but prevalent in…

  • Jenkins and its use case

    Jenkins and its use case

    Jenkins: Jenkins is a free and open source automation server. It helps automate the parts of software development…

  • AMAZON SQS USE CASE

    AMAZON SQS USE CASE

    AMAZON SQS: Amazon Simple Queue Service(SQS) is a managed message queue service offered by Amazon Web Services (AWS)…

  • Kubernetes and its use cases

    Kubernetes and its use cases

    Kubernetes: Kubernetes is an open source platform for deploying and managing containers. It provides a container…

  • How to configure webserver and python interpreter on the top of Docker

    How to configure webserver and python interpreter on the top of Docker

    Docker: Docker provides the ability to package and run an application in a loosely isolated environment called a…

  • AWS Command Line Interface

    AWS Command Line Interface

    The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and…

    2 条评论
  • How IBM uses Big Data

    How IBM uses Big Data

    Big Data: Big Data describes the large volume of data in a structured and unstructured manner. The data belongs to a…

  • How Disney+Hotstar uses AWS Cloud

    How Disney+Hotstar uses AWS Cloud

    Amazon Web Services: Amazon Web services is one the most popular cloud service provider in the world. Services of…

  • How You Tube uses Artificial Intelligence And Machine Learning

    How You Tube uses Artificial Intelligence And Machine Learning

    ARTIFICIAL INTELLIGENCE: Artificial intelligence (AI) refers to the simulation of human intelligence in machines that…

  • Developing WordPress and MySQL infrastructure with NAT gateway using Terraform

    Developing WordPress and MySQL infrastructure with NAT gateway using Terraform

    NAT gateways(Network Address Translation): NAT Gateway is a highly available AWS managed service that makes it easy to…

社区洞察

其他会员也浏览了