Terraform to launch WordPress on K8s with AWS RDS Database

Image for post
Image for post

Hello readers, in this blog i will be deploying the Wordpress application on Kubernetes locally and using AWS RDS as database for our application by using Terraform.

Necessary Requirements:

  1. AWS CLI software configured with a profile. You can get from here.
  2. Knowledge of AWS Cloud Computing and Terraform.
  3. Terraform setup. You can get from here.
  4. Minikube setup with kubectl. You can install minikube using this guide from here and kubectl from here.
  5. You can get my code from here.

Steps while performing our project:

  1. Write an Infrastructure as code using terraform, which automatically deploy the Wordpress application.
  2. From above code , also deploy RDS service for the relational database for Wordpress application.
  3. Also create Load Balancer so that our application is accessible from our workstation.

Below are the steps how you can successfully execute my code:

Step 1: Start your minikube machine.

minikube start

Step 2: Configure your aws profile with below cmd

aws configure
Image for post
Image for post

Step 3: Now below will be steps for code completion. If you are not interested then you may skip to Step 4.

  • For providing provider info of kubernetes and aws.
  • For creating rds db instance. In this case db instance will be created in default vpc. To get more options and control according to your desire you can refer here.
  • For creating k8s resources like secrets, deployments and service for load balancer.
  • For getting inputs from user like database name, username and password a variables file was created to take input from user while running code.

That’s it for coding part. Now execution part resumes.

Step 4: Go inside directory where your terraform files are present and run

terraform init

It will install all the necessary plugins for your code.

Image for post
Image for post

Step 5: Now run

terraform apply
Image for post
Image for post

Then it will ask to enter the database name, username and password and after that it will validate and prompt to enter yes to deploy whole setup.

Image for post
Image for post

Note: Databse creation takes around 5 minutes so be patient.

Step 6: You can verify your k8s infrastructure using

kubectl get all
Image for post
Image for post
Image for post
Image for post

and AWS RDS database from AWS console.

Image for post
Image for post

Step 7: Now enter your minikube ip along with Load Balancer port no. in your browser.
To get minikube ip use below command

minikube ip

and to get port no, you can see from kubectl get all command

Image for post
Image for post

Step 8: After entering correct url, you will be able to see WordPress installation page if all went successfully.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Step 9: After Logging in, you will be able to see WordPress Dashboard and you can do anything with it.

Image for post
Image for post

Here’s a demo blog published using WordPress

Image for post
Image for post

Step 10: For removing all your setup use command

terraform destroy

then it will prompt to say yes, enter yes to delete your whole setup in one go. Again it will take some time to destroy your whole setup. So be patient.

Image for post
Image for post
Image for post
Image for post

Note: You can cross-verify your resources by kubectl get all command also don’t forget to turn off your minikube by command minikube stop.

Image for post
Image for post

So that’s it folks for this blog. Hope you liked it. See you in next blog.

Github repo: https://github.com/Apeksh742/Terraform_for_wordpress_on_k8s_with_rds_db

LinkedIn Profile: https://www.linkedin.com/in/apeksh-agarwal-0543bb192/

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store