Task 23 | Launching frontend & Backend Application Multi-Node Kubernetes Cluster Using Ansible | ARTH

Gaurav Sharma
4 min readAug 26, 2021

--

Overview

In this article I am going to create a multi-node Kubernates cluster & launch one Wordpress & Mysql databse & all of this we do using Ansible playbook.

Task Description

  • Automate Kubernetes Cluster Using Ansible
  • Launch ec2-instances on AWS Cloud eg. for master and slave.
  • Create roles that will configure master node and slave node seperately.
  • Launch a wordpress and mysql database connected to it in the respectine slaves.
  • Expose the wordpress pod and client able hit the wordpress ip with its respective port.

Pre-Requisites

  • Kubernetes is an open-source COE(Container Orchestration Engine) used for automating container apps deployment, scaling, and monitor/management.
  • Ansible is a automation tool used mostly for provisioning, configuration management, we can write infrastructure as code.

I have already created a blog in which I created a blog in which i have created Ansible roles to create multi-node kubernates cluster, it’s literally cover half of this task.

Now let’s start the task.

Steps

  • First we create role For launching Master & Slave with there tags.

Now after running playbook we successfully launched 3 nodes.

  • Next we create roles for slave & master node & using join command we join slave to the master & create kubernates cluster.

#Role for Master Node

#Role for Slave Node

  • So above steps are for creating Kubernates cluster now we are going to launch two pods in the cluster so for that we need create yml files for the pods & copied them to master node.
  • Next we run kubectl create command & create the nodes.
  • I have already included expose resource in the wppod.yml file, so we don’t need to run kubectl expose command separately.
  • Now we create debug tasks for retrieving the “exposed port” & “Database host IP”.

Now include all these roles to main playbook.

Finally after running our playbook we can check the results.

  • Master-Node
  • Pods YAML files

Now lets access the Wordpress app —

  • But first need host IP & exposed port
  • For accessing the wordpress, use below URL:
http://{{Master_Node_IP}}:{{Exposed_Port}}
  • Now login to the Wordpress

Conclusion

Mistakes & learning

  • First time I failed to run the kubectl command in the respective directory. So for switching the directory we can use “chdir” parameter.
  • So this one mistake done by me unintentionally during the task is that when I launch the cluster, the IP range & flannel’s network range are different.
    By default flannel’s network range is “10.244.0.0/16", so we have two option-
    1. Use pod-network-cidr= “10.244.0.0/16” in kubeadm command.
    2. Edit flannel network range:-
    # kubectl edit configmap kube-flannel-cfg -n kube-system

    net-conf.json: |
    {
    “Network”: “10.240.0.0/16”,

    And then delete all the flannel pods
    # kubectl delete pods -l app=flannel -n kube-system

Fin.

In last I want to thank you for reading this blog.
Hope you’ve learnt something.
Also share it if you liked this blog.

--

--