Deploying WordPress On Kubernetes With Amazon RDS Using Terraform

Abhishek Chouhan
7 min readMar 5, 2021

Heyy EveryOne ..!!
In this Blog i will explain you How tO Launch Wordpress Application On The Top Of Kubernetes (Minikube) with Amazon RDS as Database Using Terraform .

Project Description :-

#DescripTion Of projectWrite an Infrastructure as code using Terraform, which automatically deploy the WordPress applicationOn 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.

Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet. AWS’s version of virtual computers emulates most of the attributes of a real computer, including hardware central processing units (CPUs) and graphics processing units (GPUs) for processing; local/RAM memory; hard-disk/SSD storage; a choice of operating systems; networking; and pre-loaded application software such as web servers, databases, and customer relationship management (CRM).

Amazon Relational Database Service (or Amazon RDS) is a distributed relational database service by Amazon Web Services (AWS). It is a web service running “in the cloud” designed to simplify the setup, operation, and scaling of a relational database for use in applications. Administration processes like patching the database software, backing up databases and enabling point-in-time recovery are managed automatically. Scaling storage and compute resources can be performed by a single API call as AWS does not offer an ssh connection to RDS instances.

Terraform is an open-source infrastructure as code software tool created by HashiCorp. Users define and provision data center infrastructure using a declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON.Terraform manages external resources (such as public cloud infrastructure, private cloud infrastructure, network appliances, software as a service, and platform as a service) with “providers”. HashiCorp maintains an extensive list of official providers, and can also integrate with community-developed providers. Users can interact with Terraform providers by declaring resources or by calling data sources. Rather than using imperative commands to provision resources, Terraform uses declarative configuration to state the desired final state. Once a user invokes Terraform on a given resource, Terraform will perform CRUD actions on the user’s behalf to accomplish the desired state. The infrastructure as code can be written as modules, promoting reusability and maintainability.

Kubernetes (commonly stylized as K8s) is an open-source container-orchestration system for automating computer application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation. It aims to provide a “platform for automating deployment, scaling, and operations of application containers across clusters of hosts”. It works with a range of container tools, including Docker. Many cloud services offer a Kubernetes-based platform or infrastructure as a service (PaaS or IaaS) on which Kubernetes can be deployed as a platform-providing service. Many vendors also provide their own branded Kubernetes distributions.

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virt

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop for users looking to try out Kubernetes or develop with it day-to-day.

WordPress (WP, is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as Themes. WordPress was originally created as a blog-publishing system but has evolved to support other types of web content including more traditional mailing lists and forums, media galleries, membership sites, learning management systems (LMS) and online stores. WordPress is used by more than 60 million websites, including 33.6% of the top 10 million websites as of April 2019, WordPress is one of the most popular content management system solutions in use.[8] WordPress has also been used for other application domains such as pervasive display systems (PDS). WordPress was released on May 27, 2003, by its founders, American developer Matt Mullenweg[1] and English developer Mike Little, as a fork of b2/cafelog. The software is released under the GPLv2 (or later) license.

Prerequisites :-

  1. AWS AccounT .
  2. IAM User In The Main Account of AWS .
  3. Terraform MusT Be Installed .
  4. AWS CLI .
  5. Minikube Should be Installed For Performing This Task .
  6. Kubectl to be Installed .
  7. Terraform plugin in vs code (its n’t necessary if you are not using vscode)

LeT’s Start

Configure AWS CLI and Create a Profile

aws configure --profile 'profile_name'

Now we are going ahead in our task so for saving our time we can start minikube .

minikube start

Now I am going to explain you the code .

This is Our or we can say that main file which has responsibility to run the code and also it will run 2 more files as declared in depends_on block of code . and this file is the one which will show us the output

This Code will Create RDS On AWS with the name , pass, storage etc. according to our requirement . and the at the last the output block will run to get ip on the console .

Wordpress Application ‘s DeploymenT will be Created In Kubernetes (Minikube) and also it will have 3 replicas and then we will get url to get the wordpress dashboard .

terraform init
terraform validate
terraform plan
terraform apply --auto-approve

It will print url for getting wordpress dashboard and rdb ip so that we can connect the wordpress and rdb without going to aws .

Now we can see that our Amazon RDS is created and now we are going to use in our wordpress application launched by terraform on the top of minikube u can see the url in above image for getting wordpress dashboard

# paste this url in browserhttp://

Giving our database details ..

Finally Here is Our Wordpress Application Launched on Minikube and having backend connectivity means database from Amazon RDS .

Same EnvironmenT that we created in above steps can be destroyed in single command i.e.

terraform destroy --auto-approve

All The Code yOu can Find On My GitHub Repo

For furthur queries or suggestion’s feel free to ConnecT with my team on Linkedin :-

THank yOu EveryOne For Reading ..!!



Abhishek Chouhan

Technology Enthusiast Like to learn new new tools and technology and integrate them, DevOps, Cloud, MLOps, Kubernetes, AWS, Terraform, Expertise in Docker…