Task 19 | Configure K8S Multi Node Cluster Using Ansible | ARTH

In this Task I’m going to create a Multi Node Kubernates Cluster using Ansible Playbook. Now let’s see task description:-

  • Ansible Role to Configure K8S Multi Node Cluster over AWS Cloud.
  • Create Ansible Playbook to launch 3 AWS EC2 Instance
  • Create Ansible Playbook to configure Docker over those instances.
  • Create Playbook to configure K8S Master, K8S Worker Nodes on the above created EC2 Instances using kubeadm.
  • Convert Playbook into roles and Upload those role on your Ansible Galaxy.
  • Also Upload all the YAML code over your GitHub Repository.
  • Create a README.md document using markdown language describing your Task in creative manner.
  • Create blog about task and share on your LinkedIN profile.
  • First we have to configure dynamic inventory. If you don’t know you can go through my blog on this topic.
  • You need to know two topics kubernates Multi Node cluster & AWS ec2 service.
  • You also need to know how to create ansible roles.
To create a role
# ansible-galaxy role init <Role_name>
To see the role in created in the role path
#ansible-galaxy role list
  • Firstly we create roles for Launching Instances, Master & Slave nodes. & include this folder path in the inventory.
Command to create ansible role
# ansible-galaxy role init <Role_name>
  • Secondly we create role for launching ec2 instances.
    Remember always store your credentials in var file.

Here I have launch three instances one is master & two are slave nodes.

  • Next I create role for master node.
  • Next we create a role for slave node.
  • Now we create a main file for ansible playbook& include all roles in the playbook.
  • For more information about manual Configuration, steps for creating this Cluster go to the below link.
  • Now it’s time to run this playbook let’s see how it goes

After so many attempts finally my playbook run with out any error.

Now let’s check all steps are completed or not.

  • Instance created
  • Master node
  • Slave node
  • Now let’s try to create a deploy in the node

It’s successfully created.
Congrats all steps are completed successfully.

Conclusion

In this task i was failed several time despite of know manual steps of creating Multinode cluster.

  • First time i was interrupted when i have to store the join command in the variable.
    Then i found register module to store the output on the fly.
  • Second time when i again run my playbook it again create all three instances despite all the instances was already present.
    From there i found a solution of including role tags. By doing this you can skip the roles or tasks of your choice using their tags while running the playbook. For further knowledge 👇
  • Third, when I have to run the join command in slave node which I have registered before in master node host.
    There i used ‘hostvars’ with group name.

At last hope you learnt something from this blog thanks for reading the article.
Thanks For Your time!!

Content

  • GitHub Repo
  • Ansible Galaxy Roles

# Role for EC2 Instance

# Role for Master Node

# Role for Slave Node

--

--

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