Watch all our Tutorials and Training Videos for Free on our Youtube Channel, Get Online Web Tools for Free on swebtools.com

Search Suggest

Install Kubernetes Cluster using Ansible Playbook Automation

install kubernetes using ansible, install kubernetes cluster using ansible, setup kubernetes cluster using ansible, kubernetes installation ansible
This post will show you how to Install Kubernetes Cluster using Ansible Playbook Automation.

You will get set of Ansible Playbooks that would help you to build a Complete Multinode Kubernetes Cluster in an automated way to deploy an containerized application.

In the previous post, we have given you the step by step procedure to install and configure kubernetes cluster manually on linux servers using kubeadm and kubectl commands.You can also refer these below mentioned related links to understand this topic from basics.

Install Kubernetes Cluster using Ansible Playbook Automation


How to Install Kubernetes Cluster using Ansible Playbook Automation



Let's get started.

kubernetes cluster configuration


We have created these ansible playbooks and stored in our github repository.

List of Files Available in this repository

ansible.cfg - Ansible configuration file created locally.
hosts - Ansible Inventory File
env_variables - Main environment variable file where we have to specify based on our environment.
settingup_kubernetes_cluster.yml - Ansible Playbook to perform prerequisites ready, setting up nodes, configure master node.
configure_worker_nodes.yml - Ansible Playbook to join worker nodes with master node.
clear_k8s_setup.yml - Delete entire configurations from all nodes.
playbooks - Its a directory holds all playbooks.

How to use this ansible playbooks: (Setup Instructions)


Also You can Watch this Tutorial video on our YouTube Channel.
"Install Kubernetes Cluster using Ansible Playbook Automation"


Once your servers are ready (one master node and multiple worker nodes), follow these below instructions.

1. Make an entry of your each hosts in /etc/hosts file for name resolution.

cat /etc/hosts
192.168.2.1 kubernetes-master.learnitguide.net kubernetes-master
192.168.2.2 kubernetes-worker1.learnitguide.net kubernetes-worker1
192.168.2.3 kubernetes-worker2.learnitguide.net kubernetes-worker2

2. Make sure kubernetes master node and other worker nodes are reachable between each other.

3. Internet connection must be enabled in all nodes, required packages will be downloaded from kubernetes official yum repository.

4. Clone this repository into your master node.

git clone https://github.com/learnitguide/kubernetes-and-ansible.git

Once it is cloned, get into the directory.

cd kubernetes-and-ansible/centos

5. Edit a file "hosts" available in "centos" directory, Just make your entries of your all kubernetes nodes along with respective ip address.

Master Node Entries
[kubernetes-master-nodes]
kubernetes-master.learnitguide.net ansible_host=192.168.2.1

Worker Node Entries
[kubernetes-worker-nodes]
kubernetes-worker1.learnitguide.net ansible_host=192.168.2.2
kubernetes-worker2.learnitguide.net ansible_host=192.168.2.3

6. Edit a file "env_variables" available in "centos" directory and provide your server details like advertise address ip and cidr range values. Dont edit any other values in this file.

ad_addr: 192.168.2.1
cidr_v: 172.16.0.0/16

7. Deploy the ssh key from master node to other nodes for password less authentication to run ansible playbooks. Generate a SSH Key pair using ssh-keygen as below.

ssh-keygen

Enter the required values or just hit enter to take the default values. Copy the public key to all nodes including your master node and make sure you are able to login into any nodes without password. Refer this link to know How to configure SSH Passwordless Login Authentication (SSH-keygen)

8. Setting up Kubernetes Cluster Nodes using Ansible Playbook.

There is a playbook called "settingup_kubernetes_cluster.yml" to setup all nodes and kubernetes master configuration. Just run this playbook using ansible-playbook command first.

ansible-playbook settingup_kubernetes_cluster.yml

9. Joining Worker Nodes

Run "join_kubernetes_workers_nodes.yml" playbook to join the worker nodes with kubernetes master node once "settingup_kubernetes_cluster.yml" playbook tasks are completed.

ansible-playbook join_kubernetes_workers_nodes.yml

Verify the configuration from master node.

kubectl get nodes

That's it, we have successfully configured our kubernetes cluster setup using ansible playbook. you can now try deploying some applications to make sure everything is working fine. Hope you have got an idea how to install kubernetes cluster using ansible.

Refer these links to Create Kubernetes Deployment, Services & Pods Using Kubectl and Create Kubernetes YAML for Deployment, Service & Pods

You can also refer these below mentioned related links to understand this topic from basics.
Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.