Hello Guys!! In this blog, We will create a Kubernetes Cluster like how we did in one of my previous blogs and then further we will launch a WordPress application connected with MySQL database inside Kubernetes Cluster on AWS and automation using Ansible.
So Let's Get Started,
Configure Kubernetes Multinode Cluster on AWS
follow this link for reference
In the above-linked blog, I have explained thoroughly how to Configure Kubernetes Multinode Cluster.
Create an Ansible role WordPress-MySQL in the same workspace, where other roles Master and Slave are there.
ansible-galaxy init role-name
To launch the WordPress we use this command
kubectl run mywp1 --image=wordpress:5.1.1-php7.3-apache
The image version is 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 use this command to launch MySQL pod
"kubectl run mydb1 --image=mysql:5.7 --env=MYSQL_ROOT_PASSWORD=redhat --env=MYSQL_DATABASE=wpdb --env=MYSQL_USER=piyush --env=MYSQL_PASSWORD=redhat".
To Expose WordPress Pod we use the following command
"kubectl expose pods mywp1 --type=NodePort --port=80"
Here, I am exposing to NodePort as the client is in the public world.
After launching the pods it takes time to launch so, We are pausing the playbook for 60 seconds so 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.
And the playbook runs successfully.
Now we can take the public of any node either master or slave with the exposed port you will landed on the WordPress login page and then enter the password and username of the MySQL database and hit the run installation button. Our WordPress application is ready !!
SEE the below-pasted images
You can check GitHub link to get more info about the playbooks.