k8s-multinode-cluster

goal:

To create the k8s-multinode cluster with one master node and multiple worker/slave nodes

pre-requisite:

  • Install ansible and configure the configuration file for it which is in /etc/ansible directory Refer this
[master]
3.6.37.121 ansible_user=ec2-user ansible_ssh_private_key_file=/root/ansible.pem ansible_connection=ssh
[slaves]
13.127.231.29 ansible_user=ec2-user ansible_ssh_private_key_file=/root/ansible.pem ansible_connection=ssh
13.233.198.137 ansible_user=ec2-user ansible_ssh_private_key_file=/root/ansible.pem ansible_connection=ssh
  • If you have to launch the ec2-instance on AWS by ansible then the IAM user with Administrator Access should be created.
  • We need private key file with .pem extension to launch the ec2-instance. Take this file in your VM .
  • We should have boto or boto3 package installed to do something in AWS. Use this command pip3 install boto OR pip3 install boto3

Solution:

  • Download this directory in /etc/ansible/roles directory
  • Configure the configuration file which is in /etc/ansible directory Refer this
  • Create the yaml file for launching the ec2-instances on AWS. node.yml file
- hosts: localhost
roles:
- role: kube_nodes

Don’t forget to add your access key and secret key of IAM user in this file

---
# vars file for kube_nodes
access_key: "A*******************************"
secret_key: "9oFlQ5*************************cpS4johW"
  • pip3 install boto OR pip3 install boto3 Install one of them which support to your OS.
  • Now download this yaml file in your working directory and run it using the command ansible-playbook node.yml .
- hosts: localhost
roles:
- role: kube_nodes
  • And then the ec2-instance will launch on AWS
  • Check your public IPs and update it in this file. Don’t forget to update your private key file name also. This file should be in the /root directory as we give this path in the ansible conf file
  • Now download main yml file in working directory and run it by the command ansible-playbook main_setup.yml
- hosts: master
roles:
- role: k8s-master1

- hosts: slaves
vars_prompt:
- name: join
prompt: "Please enter the command to join worker node with master"
private: no
roles:
- role: k8s-slave
  • Now kubernetes multinode cluster is setup

Thank you

--

--

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