WordPress deployed on the Kubernetes cluster and used rds service of aws and connect it with WordPress...
Details on Task i.e. what we gonna do?
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.
- Here I will be using minikube on top of which I will deploy WordPress, you can use eks but for the time being, I am using minikube as this problem not required a multi-node cluster so just by one i.e. single cluster, this task can be done!!!.
- let's get started with some concepts of rds and minikube and all then I will share my code here and some screenshots of end result.
- All of us know Docker so we can launch os on top of Docker in a fraction of a second but what there will be a requirement of management then we should use Kubernetes which manages Docker or Pod, Actually, it is built to manage containers or pods.
- Now there are various ways to install Kubernetes, in AWS eks is a service which provides multi-node cluster and that is a fully managed service. However here I will be using minikube to install clusters on my on-premises.
- RDS is an RDBMS kind of database provided by AWS which will be scaled automatically according to the data storage.
- To deploy WordPress On top of Kubernetes...
- I have installed Minikube and the kubectl command is configured in my system. Now I am ready to start minikube and to deploy WordPress on top of the cluster.
The terraform code goes here....
- To Deploy WordPress on top of the Minikube cluster. I started Minikube by "minikube start" command, then I ran the following code to deploy...
provider "kubernetes" { config_context_cluster = "minikube" } resource "kubernetes_deployment" "wordpress" { metadata { name = "wp" } spec { replicas = 3 selector { match_labels = { env = "production" region = "IN" App = "wordpress" } match_expressions { key = "env" operator = "In" values = ["production" , "webserver"] } } template { metadata { labels = { env = "production" region = "IN" App = "wordpress" } } spec { container { image = "wordpress:4.8-apache" name = "wp" } } } } } resource "kubernetes_service" "wordpresslb" { metadata { name = "wplb" } spec { selector = { app = "wordpress" } port { protocol = "TCP" port = 82 target_port = 82 } type = "NodePort" }
}
- Now we have to configure or create rds on top of aws...
provider "aws" { region = "ap-south-1" profile = "ranjit" } resource "aws_db_instance" "mydb" { allocated_storage = 20 identifier = "dbinstance" storage_type = "gp2" engine = "mysql" engine_version = "5.7.30" instance_class = "db.t2.micro" name = "mydb" username = "ranjit" password = "ranjit1234" iam_database_authentication_enabled = true parameter_group_name = "default.mysql5.7" skip_final_snapshot = true publicly_accessible = true tags = { Name = "sqldb" }
}
- Now we will get one URL of service i.e. node port to expose to the outside world, that we would have attached with WordPress pod. Now by the command "minikube service list" we will get that IP with the port by which we can access WordPress...
resource "null_resource" "MkubeServices"{ provisioner "local-exec"{ command = "minikube service list" } depends_on = [ kubernetes_deployment.wordpress, kubernetes_service.wordpresslb, aws_db_instance.mydb ] }
- Now you have to configure WordPress i.e. to connect with rds you have to give your rds information to WordPress, due to some security reasons I am not attaching that screenshot...
- Let's see the results...
- Here I have created one rds before that is why it showed me that already exists but no issues at all I have used that created rds service.
Thank you...