Introduction

In the previous post, we have learn kubernetes basics and understand it’s components. now in this tutorial we will see how to setup 3 nodes kubernets cluster.

There is lots of tools available to setup kubernetes like Minikube, kubeadm and Kargo

I found very simple installation using Kargo ( now knows as Kubespray ). which is just ansible playbooks.

So we can see how to setup 3 node kubernetes cluster using Kargo.

Assuming that you have ready installed 3 nodes of CentOS 7.4 or higher. you can have it on Pysical server or VM or AWS or any cloud, you just need to have ssh access to this servers.

Perquisite

yum install python-pip git 

Since Kubernetes >= 1.8, You need to disable Swap in all nodes.

Download the Kargo

git clone https://github.com/kubernetes-incubator/kubespray
cd kubespray
sudo pip install -r requirements.txt

Configuring the static inventory file

cp inventory/sample/hosts.ini inventory/hosts
vim inventory/hosts

# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
node1 ansible_ssh_host=my-host01 ip=1.1.1.1
node2 ansible_ssh_host=my-host02 ip=1.1.1.2
node3 ansible_ssh_host=my-host03 ip=1.1.1.3

# ## configure a bastion host if your nodes are not directly reachable
# bastion ansible_ssh_host=x.x.x.x

[kube-master]
node1
node2
node3

[etcd]
node1
node2
node3

[kube-node]
node1
node2
node3

[k8s-cluster:children]
kube-node
kube-master

Test connection

ansible -i inventory/hosts all -m shell -a 'uptime'

Configure variables

cp -a inventory/sample/group_vars inventory/group_vars
vim inventory/group_vars/k8s-cluster.yml
kube_basic_auth: true

It will generate random password and assign to admin user and it will store in inventory/credentials/kube_user

Installing Kubernetes

ansible-playbook -i inventory/hosts cluster.yml -vv --become

In case if you face any issue, you can run reset.yml playbook

Once installation is finished, you can login to node1 and check the status using following command.

kubectl get nodes