Install Kubernetes Cluster using Ansible Playbook Automation

kubernetes ansible, kubernetes ansible playbook, kubernetes using ansible, install kubernetes cluster using ansible, deploy kubernetes using ansible

This post gives you an set of Ansible Playbook 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.
What is Kubernetes - Learn Kubernetes from Basics
Create Kubernetes Deployment, Services & Pods Using Kubectl
Create Kubernetes YAML for Deployment, Service & Pods
What is Docker - Get Started from Basics - Docker Tutorial
What is Container, What is Docker on Container - Get Started
How to Install Docker on CentOS 7 / RHEL 7
Docker Images Explained with Examples - Docker Tutorial
How to Run Docker Containers - Explained with Examples

These playbooks will work on any physical servers, virtual machines, aws cloud, google cloud or any other cloud servers. This has been tested and verified on Centos 7.3 64 bit operating systems.



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.
[youtube src="kMKkpgB6IwM" height="315" width="560" /]


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.
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.
What is Kubernetes - Learn Kubernetes from Basics
What is Docker - Get Started from Basics - Docker Tutorial
What is Container, What is Docker on Container - Get Started
How to Install Docker on CentOS 7 / RHEL 7
Docker Images Explained with Examples - Docker Tutorial
How to Run Docker Containers - Explained with Examples

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.
YouTube | Facebook | Twitter | Pinterest | Rss 
kubernetes, kubernetes ansible, kubernetes ansible playbooks, kubernets using ansible, install kubernetes with ansible, ansible playbook, deploy kubernetes using ansible, kubernetes ansible deployment, setup kubernets using ansible, install kubernetes cluster using ansible
January 20, 2019

Post a Comment

[disqus][facebook][blogger]

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget