Hybrid Multi Cloud Task-6,to deploy the wordpress application using kubernetes and AWS

Vamsi Mathala
6 min readJul 17, 2022

--

Steps to be performed..

  • Write an Infrastructure as code using terraform, which automatically deploy the Wordpress application.
  • On AWS, use RDS service for the relational database for Wordpress application.
  • Deploy the 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.

Prerequisites..

For performing this task ,I’m going to use my personal workstation where i have minikube setup already installed.

  • AWS account
  • Workstation with Minikube installed
  • Kubectl -K8’s client program
  • Terraform tool setup,to write and run the code to automate the things.

What is Kubernetes..🤔🤔

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation.

Containers are a good way to bundle and run your applications. In a production environment, you need to manage the containers that run the applications and ensure that there is no downtime. For example, if a container goes down, another container needs to start. Wouldn’t it be easier if this behavior was handled by a system?

That’s how Kubernetes comes to the rescue! Kubernetes provides you with a framework to run distributed systems resiliently. It takes care of scaling and failover for your application, provides deployment patterns, and more.

Then what minikube do for us …for K8's..🤔

Minikube is the name of a go program that builds a Kubernetes cluster in a single host with a set of small resources to run a small kubernetes deployment.

It is meant for testing scenarios of kubernetes (creating pods, services, managing storage, network ingress rules, etc) but in the local environment for the developer or administrator to test.

Now to create a kubernetes cluster in your workstation using minikube …go through this link.

what is the need of kubectl program..now??

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.

You can now configure your kubectl program by following this link..

Now,we are comfortable in how to work with kubernetes ..so now let’s move onto the task and make it step by step …by understanding.

Terraform code to deploy wordpress application…

Here, i’m going to deploy the wordpress application as a container on top of kubernetes cluster provided by my minikube setup.

Before I launch the wordpress application,I want to create the backend say, database for my wordpress ..so that we can configure the things automated.

Now , for database we can go for mysql container and launch it again by using kubernetes but as per the task I’m going to use AWS ,RDS (Relational Databases Service).

Confused with 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. It frees you to focus on your applications so you can give them the fast performance, high availability, security and compatibility they need.

Amazon RDS is available on several database instance types — optimized for memory, performance or I/O — and provides you with six familiar database engines to choose from, including Amazon Aurora, PostgreSQL, MySQL, MariaDB, Oracle Databse, and SQL Server.

Now,we are going to use MySQL database engine for our wordpress.Let’s create a database using terraform code.

Login to AWS ..using profile.

Create the Database-instance with required options..

Now, let’s deploy the wordpress container in top of Kubernetes..

For this,we first register our minikube as provider for terraform..

Now,create the deployment of wordpress as follows..using the terraform code..

resource "kubernetes_deployment" "Wordpress-deploy" {
metadata{
name= "wordpress"
labels ={
app = "wordpress"
env = "task-env"
}
}
spec {
replicas = 1
selector {
match_labels = {
app = "wordpress"
env = "task-env"
}
}

template {
metadata {
labels = {
app = "wordpress"
env = "task-env"
}
}
spec {
container{
name = "mywordpress"
image = "wordpress"

env{
name = "WORDPRESS_DB_HOST"
value = aws_db_instance.myrdsdb.address
}
env{
name = "WORDPRESS_DB_USER"
value = aws_db_instance.myrdsdb.username
}
env{
name = "WORDPRESS_DB_PASSWORD"
value = aws_db_instance.myrdsdb.password
}
env{
name = "WORDPRESS_DB_NAME"
value = aws_db_instance.myrdsdb.name
}
}
}
}
}
}

In the above kubernetes deployment resource we used the template with specification of container ,where we used wordpress image and the environment variables supported by the wordpress image to configure the database instance details automatically.

Now, after launching the deployment , we should expose our wordpress using the kubernetes service ..so that outside world can access to the site.

Expose the wordpress to public..

When you expose our app by creating a Kubernetes service of type NodePort, a NodePort in the range of 30000–32767 and an internal cluster IP address is assigned to the service. The NodePort service serves as the external entry point for incoming requests for your app.

Terraform code to expose :

You can verify the deployment, pod and service created for our wordpress application using the following commands..

Thus,we now have the required code to complete the task…and to get the outputs accordingly as shown above ..we should run the complete terraform code as follows..

terraform init

terraform init — this command will initializes the required backends to run the code.

terraform apply…

terraform apply — auto-approve ,this command will create entire setup as above shown..outputs.

Now as the entire setup created ..to access the website we use the ip address of the minikube and port number which is used to expose our deplyment.

To retrieve the ip address of the minikube run the command:

*minikube ip*

Finally,let’s access the wordpress and complete the installation.

Finally create a post to check…here is my post created for you.

Now let’s destroy the entire setup using a single click.

terraform destroy

terraform destroy — auto-approve , this command will delete the entire set up that’s been created.

That’s all for the task..which is completed under the mentorship of Mr.Vimal Daga sir from Hybrid Multi Cloud Training.

Thank you for reading..feel free to connect for reviews and suggestions.

Github Repo:

Signing off for now…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Vamsi Mathala
Vamsi Mathala

Written by Vamsi Mathala

CSE undergraduate, highly interested to work on industry technologies.

No responses yet

Write a response