Making ansible roles to automate the deployment of k8s cluster on AWS with wordpress-mysql application on it

Deepanshu Yadav
Towards AWS
Published in
3 min readMay 24, 2021

--

For this, we would make 3 roles which would be deploying the k8s cluster on aws, and then we will write one more playbook to launch WordPress and MySQL pods over them.

To know how to launch k8s cluster on aws by making ansible roles, see my previous story👇

🍤so, now our cluster is running and now we can launch pods in it. we can do this manually also, but we will use ansible to run the commands to create WordPress and MySQL pods. Let's see the playbook👇

so, let's see step by step whats in there👲

  1. First, I have used the vars_promp module to ask 6 variables from the client i.e. pod name for MySQL, pod name for wp, MySQL root password, MySQL user name, MySQL password of that user, and database name.🔰

2. Then we have used the command module 3 times to give 3 commands, one to launch MySQL pod, 2nd time to launch the wp pod, and the last one to expose the wp pod so that anyone can access it.🎈

Note that we have used jinja to use the same variables as the user gives while running the playbook.

3. Finally using the debug module, we are printing the port so that we can access our wp application.✨

Now, let's run this playbook. cluster is already there see below👇

after running below is the output👇

✨see I have given all the credentials, we can use secret also for this. In the last ss, I have highlights the port our wp is exposed on. pick up your cluster’s worker node IP and open it in the browser with this port as shown and then you will get your wp app running✨.

Now you can give your credentials and connect to MySQL and start using it!

You can also see by login to your instance and describe pods and seed pod with all same specifications that we gave has been launched👇

--

--