Launching WordPress_MySQL Application On the K8s Cluster in AWS Using Ansible..

By Provisioning the AWS instance launch a WordPress_MySQL application on K8s Cluster Using Ansible..

Hello All..!!

Here I am come with very interesting article which will help you a lot. By seeing name you can guess ….Yes..!!.In this article we are going to launch an WordPress application having MySQL Database on the top of Kubernetes Cluster which we create on AWS by provisioning instances using ansible.

Before doing all this thing first we have to know basic information about this services and applications. So let’s see …

Kubernetes :

Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation. Kubernetes defines a set of building blocks (“primitives”), which collectively provide mechanisms that deploy, maintain, and scale applications based on CPU, memory or custom metrics.

Amazon Web Service (AWS) :

Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet. AWS’s version of virtual computers emulates most of the attributes of a real computer, including hardware central processing units (CPUs) and graphics processing units (GPUs) for processing; local/RAM memory; hard-disk/SSD storage; a choice of operating systems; networking; and pre-loaded application software such as web servers, databases, and customer relationship management (CRM).

Ansible :

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code.It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks.

MySQL :

MySQL is free and open-source software under the terms of the GNU General Public License, and is also available under a variety of proprietary licenses. MySQL was owned and sponsored by the Swedish company MySQL AB, which was bought by Sun Microsystems (now Oracle Corporation).In 2010, when Oracle acquired Sun, Widenius forked the open-source MySQL project to create MariaDB.

Now , It’s time to move towards our task …

Let’s Started…

Creating Virtual Private Network On AWS :

Now here first we have to create a Virtual Private Network on AWS . It is because we are launching our instances on that VPC and Subnet. Here we also create a Internet Gateway , Security Group and Routing Table.

For creating all this thing we create a role and in that we do tasks as follow..

Create a Virtual Private Network

Creating a VPC Internet Gateway

Creating the Subnet On that VPC

Create a Security Group

And Create a Routing Table

Here I am created VPC as a role for configure all this above things..

“ ansible-galaxy init vpc ”

Now write the code of vpc and other services in a /tasks/main.yml file of that vpc role.

And here we give some variables in a /vars/main.yml file which we use in our tasks/main.yml file.

Now , here our code for vpc completed . So now we have to run this role by creating playbook for it. In my case I am create a vpc.yml playbook for running this role.

Here our playook run successfully. So let’s check the resources which we want to create are launched or not..

Our VPC
Our Subnet
Our Route Table
Our Internet Gateways
Our Security Group

Here our all basic services created successfully. So our next step is launching the EC2 instances on that vpc-subnet. Here we launch the instances for master and slave node of cluster.

EC2 Instance Provisioning :

Here we launch one instance for master and two instance for the slave node. For that we create other role . And here I am create a ec2_pro role for ec2 provisioning.

“ ansible-galaxy init ec2_pro ”

Now in that role we write code for ec2 provisioning. Here we have to write code in /tasks/main.yml file.

Now write a playbook for running this role. Here I am created a ec2_pro.yml playbook. Now here we are going to run this playbook..

Now our playbook run without any error. So let’s check the launched instance on AWS.

Now put the IP of that nodes in a inventory file by doing dynamic inventory method. For that we have to put two files in a base OS and that is ec2.py and ec2.ini file. And play ec2.py file and put our access and secret key in the ec2.ini file.

https://raw.githubusercontent.com/ansible/ansible/stable-1.9/plugins/inventory/ec2.py

https://raw.githubusercontent.com/ansible/ansible/stable-1.9/plugins/inventory/ec2.ini

Now Let’s move towards our important setup of this task. And that is configure master node and worker nodes.

Here we have to configure two part one is master node and other is a slave node . So first we have to first configure the master node.

Configure Master Node :

Here for configure the master node we have to create new role and that is kube_master.

“ ansible-galaxy init kube_master ”

Now in that we have to configure following steps..

  1. Installing docker and iproute-tc
  2. Configuring the Yum repo for kubernetes
  3. Installing kubeadm,kubelet kubectl program
  4. Enabling the docker and Kubernetes
  5. Pulling the config images
  6. Configuring the docker daemon.json file
  7. Restarting the Docker service
  8. Configuring the Ip tables and refreshing sysctl
  9. Starting kubeadm service
  10. Creating .kube Directory
  11. Copying file config file
  12. Installing Addons e.g flannel
  13. Creating the token
  14. Store token in a file

And in /vars/main.yml file give the IP range for flannel.

Here our code for configuring master is created . We have to create playbook for running that role. And in my case I am created a k8s_master.yml playbook for run role. After that run this playbook for configure the master node.

Here our master node configured successfully.

Now it’s time to configure the slave nodes.

Configure Slave Node :

Here for configure the master node we have to create new role and that is kube_slave.

Steps for configure the slave node :

  1. Installing docker and iproute-tc
  2. Configuring the Yum repo for kubernetes
  3. Installing kubeadm,kubelet kubectl program
  4. Enabling the docker and Kubernetes
  5. Pulling the config images
  6. Configuring the docker daemon.json file
  7. Restarting the Docker service
  8. Configuring the Ip tables and refreshing sysctl
  9. Copy the join command which we store while configure master.
  10. Run join command.

Now here our role for slave is done for running it we have to create a playbook and here I am create a k8s_slave playbook file. And I am going to run it..

Here our slaves also configured successfully. So here our cluster also created. We can see our slaves are attached to master or not in master node.

You can see our slaves are connected to master and our cluster created successfully.

Now, here our cluster is created. So our next and important part is launching a WordPress and MySQL application on the kubernetes cluster which we created above.

Lunching WordPress and MySQL on Cluster :

So for that also we have create a role and in my case I am created a wp_sql as a role.

“ ansible-galaxy init wp_sql ”

In this role we configure below things:

  1. Launching WordPress application
  2. Launching MySQL application
  3. Exposing the WordPress application

Now after creating a role we have to create a playbook for running that playbook. In my case I am creating a wp_sql.yml as a playbook file. Now , run this playbook for configure the WordPress and MySQL application on the cluster.

Here you can see our playbook run successfully. That means we successfully deploy the WordPress and MySQL on the cluster.

The MySQL-WordPress playbook is written in such a way that it will show the IP and Ports of database while running.

Now let’s take the IP of any node and port which is given here and check the output..

After that it open the WordPress Website..

Yes ….!! Our Task is completed Successfully..

I hope this article help you a lot and you also deploy WordPress and MySQL application successfully.

Below is an GitHub link for entire cluster and application deploy code..

If you have any issue in this article then connect me on LinkedIn..

Thank you so much for visiting the Article…

Have a Great Day.. :)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store