Task -6 Hybrid Multi-Cloud

Hiteshkoolwal
4 min readOct 18, 2020

TASK

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 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.

5). In this setup, WordPress will be running on the Kubernetes in the local system and connected with the database running on the cloud i.e AWS.

Procedure

1) Providing service provider information to terraform.

2) Creating a Security Group for relational database service.

Creating the Security group allowing the port number 3306 which will allow incoming traffic to MySQL.

When the above code is executed using the Terraform apply command, it will result in the creation of the security group allowing port number 3306 for MySQL.

3) Launching the Database service for WordPress.

Now launching the RDS(Relational database service) in AWS this database will act as a storage unit for WordPress.

When the above code is executed using the Terraform apply command it will result in the creation of the database in the AWS.

4) Launching Kubernetes

Launching the Kubernetes service in the local system using the Terraform code and creating the separate namespace for the Terraform.

The above code will result in the creation of a separate namespace for the Kubernetes.

5) Creating the Persistent Volume Claim (PVC)

Persistent volume claim will request the storage from the user’s local system, with the help of PV we can achieve the data availability i.e due to any reason if the WordPress goes down the data associated with the WordPress will not be lost and new WordPress O.S will be launched with zero latency time.

When the above code is executed using the Terraform apply command it will result in the creation of 2GB local storage connected to the WordPress database instance.

6) Launching the WordPress pod using deployment over Kubernetes.

Launching the Kubernetes pod using deployment because deployment is the one who keeps on monitoring the pod(O.S) launched and if the pod goes down, the deployment is the one who launches the new pod with the same configuration with zero latency time.

resource "kubernetes_deployment" "wordpress" {
depends_on = [kubernetes_persistent_volume_claim.wordpress_pvc]
metadata {
name = "wordpress"
namespace = kubernetes_namespace.NS.id
labels = {
Env = "wordpress"
}
}
spec {
replicas = 1
selector {
match_labels = {
Env = "wordpress"
}
}
template {
metadata {
labels = {
Env = "wordpress"
}
}
spec {
container {
name = "wordpress"
image = "wordpress:4.8-apache"
env{
name = "WORDPRESS_DB_HOST"
value = aws_db_instance.my_db.address
}
env{
name = "WORDPRESS_DB_USER"
value = aws_db_instance.my_db.username
}
env{
name = "WORDPRESS_DB_PASSWORD"
value = aws_db_instance.my_db.password
}
env{
name = "WORDPRESS_DB_NAME"
value = aws_db_instance.my_db.name
}
port {
container_port = 80
}
volume_mount{
name = "pv-wordpress"
mount_path = "/var/lib/pam"
}
}
volume{
name = "pv-wordpress"
persistent_volume_claim{
claim_name = kubernetes_persistent_volume_claim.wordpress_pvc.metadata[0].name
}
}
}
}
}
}

When the above code is executed using the Terraform Apply command it will result in the creation of the WordPress pod using deployment.

Now we have a WordPress pod ready which is running in our local system and it connected with the Relational database service(RDS) in AWS.

7) Exposing the pod.

The WordPress pod is ready but the outside world i.e internet will not have connectivity with it so we need to expose the pod so that the outside world can have connectivity with it.

When the above code is executed using Terraform apply command the pod will be exposed to the internet on port number 80 i.e HTTP.

8) WordPress will be launched.

Thus we can see that using the minikube IP of the system and port number provided, WordPress is launched with the database connected to it in the backend which is running on servers of AWS.

Destroying the complete infrastructure after solving the use case.

terraform destroy

Thanks for reading the article.

--

--