Launching WordPress with MySQL Database in K8S Cluster on AWS Using Ansible
- Hello there !!! So in this blog we will be launching a WordPress application connected with MySQL database inside Kubernetes Cluster on AWS & it’s automation using Ansible.
- Configuration of Kubernetes Multi-node Cluster on AWS
My blog link for your reference :
- In the above-linked blog, I have explained thoroughly how to Configure Kubernetes Multi-node Cluster.
Further Steps to follow :
- Create an Ansible role WordPress-MySQL in the same workspace, where the other roles such as Master and Slave are present.
ansible-galaxy init role-name
- In the “ main.yml ” file inside the tasks directory of the WordPress-MySQL role, write down the following code —
Wordpress-MySql-K8S-Cluster-AWS-Ansible/main.yml at main ·…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below…
- Now in the above tasks, we have launched WordPress and MySQL respectively.
- To launch the WordPress we use the following command :
kubectl run mywp1 — image=wordpress:5.1.1-php7.3-apache
- The image refers to the image version “ wordpress:5.1.1-php7.3-apache ”
- Also to launch the MySQL pod we have to set the user name and password, here we can use the secret resource Kubernetes but we can also use the following command to launch MySQL pod :
kubectl run mydb1 — image=mysql:5.7 env=MYSQL_ROOT_PASSWORD=redhat env=MYSQL_DATABASE=wpd — env=MYSQL_USER=piyush — env=MYSQL_PASSWORD=redhat
// It is a single command
Exposing WordPress pod
- To Expose WordPress Pod we can use the following command :
kubectl expose pods mywp1 — type=NodePort — port=80
- Here, I am exposing to Node Port as the client, is in the public world.
Pausing the playbook
- After launching the pods it takes time to launch, so we are pausing the playbook for 60 seconds so till then all the pods will be ready.
- Creating the main playbook to run all three roles Master, Slave, and WordPress-MySQL —
- Here, In this main Playbook, we have included all the roles - Master, Slave, WordPress-MySQL which configures Kubernetes Master Node, Slave Node, and launches the WordPress and MySQL pods.
- Finally, run the main playbook using the following command —
- Our playbook executed successfully.
- Now we can take the public IP of any node either master or slave with the exposed port & you will land on the WordPress login page & then enter the password & username of the MySQL database & hit the run installation button, our WordPress application is ready.
- Finally, we successfully deployed our Wordpress application with MySql DB in K8S Cluster on AWS using Ansible & exposed it’s port for client.
- Github repository link for reference :
- Thank you for reading & learning with me.