WordPress Deployment on Kubernetes Using AWS RDS.

WordPress Deployment on Kubernetes Using AWS RDS.

Task in Hand :

  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.

Note : Here, I am using Minikube for deploying Wordpress. Minikube is used to run a single-node Kubernetes cluster inside a Virtual Machine (VM).

About AWS RDS(Relational Database Service)Amazon Relational Database Service is a distributed relational database service by Amazon Web Services. It is a web service running "in the cloud" designed to simplify the setup, operation, and scaling of a relational database for use in applications. 

Pre-requisites for the task:

1) We need AWS user, here I have used AWS IAM user of administrative access.

2) For deploying wordpress on the top of minikube, you should have minikube installed.

3) You should have Kubectl configured in your system.

Now lets start the completion procedure:

we will start by starting the minikube, if you have minikube installed use the following command.

# minikube start
  1. Terraform code to deploy wordpress on Kubernetes -
provider "kubernetes" {
  config_context_cluster = "minikube"
}
resource "kubernetes_service" "webservice" {
  metadata {
    name = "wordpress"
  }
  spec {
    selector = {
      app = "wordpress"
    }
    session_affinity = "ClientIP"
    port {
      port        =    80
      target_port = 80
      node_port = 30000
    }
type = "NodePort"
  }
}
resource "kubernetes_deployment" "deployment" {
  metadata {
    name = "wordpress"
    labels = {
       app = "wordpress"
    }
  }
spec {
    replicas = 3
selector {
      match_labels = {
         app = "wordpress"
      }
    }
template {
      metadata {
        labels = {
          app = "wordpress"
        }
      }
spec {
        container {
          image = "wordpress"
          name  = "wordpress"
        }
      }
    }
  }
}

we may as well add the provider of AWS so that when we run the init command terraform will also download the Plugins for AWS along with Kubernetes.

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

Now to initialize the folder use the following command.

# terraform init
No alt text provided for this image

now to check the execution plan use the following command -

# terraform plan
No alt text provided for this image

Now to finally deploy the Kubernetes Infrastructure use the following command -

# terraform apply --auto-approve
No alt text provided for this image

now to see the infrastructure on minikube use the following command -

# kubectl get all
No alt text provided for this image

2. Terraform code to launch MySQL database on AWS RDS -

resource "aws_db_instance" "mysql" {
  allocated_storage    = 20
  storage_type         = "gp2"
  engine               = "mysql"
  engine_version       = "5.7.30"
  instance_class       = "db.t2.micro"
  name                 = "arun_sql"
  username             = "Arun"
  password             = "#ArunKumar"
  parameter_group_name = "default.mysql5.7"
  publicly_accessible  = true
  iam_database_authentication_enabled = true
  skip_final_snapshot  = true
}

Note : we have already defined the AWS provider earlier.

now to check the execution plan use the following command -

# terraform plan

No alt text provided for this image

Now to Build the RDS Infrastructure use the following command -

# terraform apply --auto-approve
No alt text provided for this image

Now if you will check into your AWS Console you will find a RDS DB made by terraform.

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

Now to check the hosted Wordpress website use the following command -

# minikube service wordpress --url
No alt text provided for this image

go to the given url -

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

Now give the credentials you provided for your database and use the AWS DB-Identifier as the Host for the DataBase -

No alt text provided for this image

Then you will be Able to see the WordPress DashBoard.

No alt text provided for this image

Here, we have successfully deployed wordpress application.

Now, to destroy this entire infrastructure use the following command -

# terraform destroy --auto-approve
No alt text provided for this image

Thank You for Reading !!

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

Arun Kumar D的更多文章

社区洞察

其他会员也浏览了