Mastering Three-Tier Architecture: Deploying WordPress and MySQL on Kubernetes

mdshamsfiroz
4 min readOct 31, 2024

--

In this guide, we’ll walk through the process of setting up a three-tier architecture on Kubernetes using WordPress as the front end and MySQL as the backend database. We’ll provide practical steps for you to follow along.

Setting up MySQL

Let’s start by deploying MySQL, the backbone of our three-tier architecture.

Start minikube

minikube start driver=virtualbox  --no-vtx-check
  1. Create a MySQL deployment:
kubectl create deployment mysqldeployment --image=mysql

Set environment variables for MySQL:

kubectl set env deployment mysqldeployment \
MYSQL_ROOT_PASSWORD=redhat \
MYSQL_DATABASE=blogdb \
MYSQL_USER=vimal \
MYSQL_PASSWORD=redhat

Expose the MySQL deployment:

kubectl expose deployment mysqldeployment --port 3306

Setting up WordPress

Now that MySQL is running, let’s deploy WordPress.

Create a WordPress deployment:

kubectl create deployment wpdeploy --image=wordpress:latest

Expose the WordPress deployment:

kubectl expose deployment wpdeploy --type=NodePort --port=80

Connecting WordPress to MySQL

To connect WordPress to MySQL, you’ll need to configure WordPress with the MySQL service details. You can do this by accessing the WordPress configuration page through your browser.

  1. Get the Minikube IP:
minikube ip

Get the NodePort for the WordPress service:

kubectl get services wpdeploy

1. Access WordPress in your browser using the Minikube IP and NodePort.

2. In the WordPress setup, use the following database details:

  • Database Name: blogdb
  • Username: vimal
  • Password: redhat
  • Database Host: mysqldeployment (this is right ignore image ss written text localhost)
  • Table Prefix: wp_

Finally as I have done you can also be able to launch the Wordpress website.

Challenges and Future Improvements

While this setup works, it has some limitations:

  1. Dynamic Pod IP Changes: If the MySQL pod is recreated, its IP address will change, potentially breaking the connection.
  2. Security Vulnerabilities: Sensitive information is exposed in clear text.
  3. Data Integrity Concerns: Deleting the database pod will result in data loss.

In a future blog post, we’ll address these challenges by using Kubernetes resources like ConfigMaps, Secrets, and PersistentVolumes, and we’ll deploy the entire application using YAML files for better manageability.

Practical Exercise

To get hands-on experience, follow these steps:

  1. Ensure you have Minikube and kubectl installed on your system.
  2. Start Minikube: minikube start
  3. Run the MySQL and WordPress deployment commands as shown above.
  4. Access the WordPress setup page and configure it to connect to MySQL.
  5. Explore the deployed resources:
  • List all pods: kubectl get pods
  • List all services: kubectl get services
  • View pod logs: kubectl logs <pod-name>

By following these steps, you’ll have a basic WordPress and MySQL setup running on Kubernetes. This practical exercise will give you a good foundation for understanding how multi-tier applications can be deployed on Kubernetes.Remember, this is a basic setup for learning purposes. In a production environment, you’d need to consider security, scalability, and persistence, which we’ll cover in future posts.

So, whether you’re a tech enthusiast, a professional, or just someone who wants to learn more, I invite you to follow me on this journey. Subscribe to my blog and follow me on social media to stay in the loop and never miss a post.

Together, let’s explore the exciting world of technology and all it offers. I can’t wait to connect with you!”

Connect me on Social Media: https://linktr.ee/mdshamsfiroz

Happy coding! Happy learning!
Happy Kubernetes learning!

--

--

mdshamsfiroz
mdshamsfiroz

Written by mdshamsfiroz

Trying to learn tool by putting heart inside to make something

No responses yet