Deploying WordPress Application on Kubernetes with AWS RDS using Terraform.
Task Description
- Write an Infrastructure as code using Terraform, which automatically deploys the WordPress application.
- On AWS, use RDS service for the relational database for WordPress application.
- Deploy WordPress as a container either on top of Minikube or EKS or Fargate service on AWS.
- The WordPress application should be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.
Kubernetes
Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. Kubernetes help in runs containers on those instances with processes for deployment, maintenance, and scaling for Kubernetes I am using minikube. Minikube is an open-source tool that helps to run Kubernetes on a local computer
AWS RDS Amazon Relational Database Service (Amazon 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.
Let’s Get Started
Step 1: Create an AWS profile and AWS login credentials and passwords.
Step 2: Create infrastructure as code using Terraform, which automatically deploys an application on minikube.
provider "kubernetes" { config_context = "minikube"}resource "kubernetes_deployment" "wps" { metadata { name = "wordpress" } spec { replicas = 3 selector { match_labels = { "env" = "development" "loc" = "IN" "site" = "Wordpress" } } template { metadata { labels = { "env" = "development" "loc" = "IN" "site" = "Wordpress" } } spec {
container { image = "wordpress" name = "wp" } } } }}resource "kubernetes_service" "example" {metadata { name = "terraform-example"}spec { selector = { site = kubernetes_deployment.wps.spec[0].template[0].metadata[0].labels.site } port { node_port = 30001 port = 8080 target_port = 80 } type = "NodePort" }}
Run the command :
terraform init
terraform apply
Step 3: On AWS, use RDS service for the relational database for WordPress application. Terraform code
provider "aws" { region = "ap-south-1" profile = "rohit"}resource "aws_db_instance" "new"{ engine = "mysql" engine_version = "5.7.30" name = "mydb" username = "root" password = "9a17e51792" instance_class = "db.t2.micro" allocated_storage = 10 storage_type = "gp2" port = 3306 auto_minor_version_upgrade = true publicly_accessible = true parameter_group_name = "default.mysql5.7" skip_final_snapshot= true}
output "db"{ value = aws_db_instance.new.name}output "username"{ value = aws_db_instance.new.username}output "password"{ value = aws_db_instance.new.password}output "RDS" { value = aws_db_instance.new.endpoint}
we have to fill all the information of the database
GitHub Link: https://github.com/rohitraut3366/wordpress_kubernetes_AWS-RDS.git
LinkedIn: https://www.linkedin.com/in/rohit-raut-71b8a119a/
I hope you had found this article interesting !!
Thank You !!