Skip to main content

Command Palette

Search for a command to run...

Deploy the WordPress application on Kubernetes and AWS RDS using terraform

Published
3 min read
Deploy the WordPress application on Kubernetes and AWS RDS using terraform

Deploy the WordPress application on Kubernetes and AWS RDS using terraform

Infrastructure as code using Terraform, which automatically deploys the WordPress application using AWS RDS service.

What do we want to do?

Deploy the WordPress application on Kubernetes and AWS using terraform including the following steps;

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 on top of Minikube.

4. The WordPress application should be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.

My main intention is to show how we can use the RDS service of AWS in our WordPress application. Here I am using WordPress application on Kubernetes over Minikube.

Pre-requisite :

  1. AWS account.
  2. Download AWS CLI and Configure it.
  3. Download terraform. Download
  4. Download Minkube.

Let’s Start…

1. Configure the Providers

We want to use two services AWS and Kubernetes. for that we need to use AWS and Kubernetes providers in Terraform.

Providers

2. Start Minikube

To start Minikube open VirtualBox and start manually or give the command

$ minikube start

minikube start

3. Create RDS Service

We want to use RDS to store the WordPress database. so we will use MYSQL community edition.

first, we will create a security group that will allow traffic only for MySQL port.

Security Group

Now we will create an RDS instance for MYSQL.

RDS

Here we have taken 20GB Memory and t2.micro type for RDS instance. Added username and password attributes. You need to put your specifications. or you can also use a variable to take interactive input.

3. Launch WordPress on K8s

Here, for this demo, I am using locally installed minikube but you can use services like EKS or target services on AWS.

Create deployment for WordPress.

using deployment we will achieve high availability. I have selected WordPress 4.8-apache container. The main part here is we are setting some variables of WordPress like WORDPRESS_DB_HOST, WORDPRESS_DB_USER, WORDPRESS_DB_PASSWORD, WORDPRESS_DB_NAME. To set these properties we are getting values to form the RDS instance. but to access WordPress, we need to expose it.

Expose WordPress.

expose

Above kubernetes_service resource selects our WordPress pod and give service as Nodeport and exposing it.

3. Check output

output

The above code gives the URL and port number where WordPress is exposed. To get the first half of the URL which I had put statically here. you can check using below command

$ minikube ip

Select language and add admin details. after that, you will see the login tab like below.

login

Add Post

Publish and Check.

You will see the output like above.

Check the solution

Now delete the pod manually and it will be launch again…

Again check WordPress our previous blog exists or not.

Conclusion

We have successfully created Infrastructure as Code for deploying the WordPress application on Kubernetes and AWS RDS using terraform

I want to express my gratitude for everything that Mr. Vimal Daga sir have helped me achieve this knowledge and thank you for the cheering and mentoring us…..

If you like my efforts then don’t forget to give feedback in the comment box. Feel free to ask questions and doubts in the comments.

#LEARN — SHARE — GROW

More from this blog

SREngineered - Shubham Rasal

26 posts

SREngineered Shubham Rasal - Inviting pragmatic engineers passionate about the craft. Delve into Kubernetes, AWS, Docker, Ansible, Golang, and more. Let's master engineering together!