Setting up a Kubernetes multi-node cluster

In this post we’ll go through step by step instructions on how to setup a multi-node Kubernetes cluster. We’ll be using centos vm’s for the purpose of this post

Setting up the Master node

1 – Disable swap

The idea of kubernetes is to tightly pack instances to as close to 100% utilized as possible. All deployments should be pinned with CPU/memory limits. So if the scheduler sends a pod to a machine it should never use swap at all. You don’t want to swap since it’ll slow things down.

swapoff -a

2 – Remove the swap reference from the fstab file (/etc/fstab)

#/root/swap swap swap sw 0 0

3 – Disable SELinux enforcement

setenforce 0

4 – Change SELinux to permissive (/etc/selinux/config)

SELINUX=permissive

5 – Install Docker

sudo yum install -y docker

6 – Start and Enable docker

systemctl start docker
systemctl enable docker

7 – Create the kubernetes repo file

cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

8 – Install the kubernetes packages kubelet, kubeadm,
kubectl

sudo yum install -y kubelet kubeadm kubectl

9 – Start and Enable kubelet

systemctl enable kubelet
systemctl start kubelet

10 – Network changes for containers

cat <  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

11 – And for the above network setting to take place execute the below command

sysctl --system

12 – Set the pod network CIDR

kubeadm init --pod-network-cidr=10.244.0.0/16
Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join --token 6065d6.90ab98e756bd01b3 172.31.123.145:6443 --discovery-token-ca-cert-hash sha256:611b3df6515064293e1a8c7583a64f9d72e660c68011d981d6759b7017311c7b

note down the above token command which will be later used on the worker nodes to join this master

Set the proper permissions to the kube config

mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

13 – Apply ip address to containers using flannel(flannel is a virtual network that attaches IP addresses to containers)

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml

Check the nodes using kubectl

 
[root@nikhitkumar4 user]# kubectl get nodes
NAME                           STATUS     ROLES     AGE       VERSION
nikhitkumar4.server.com   Ready      master    2d        v1.9.2

Our master is ready.

Now that our master node is ready lets set up our worker node. Follow the same steps on the worker nodes. once you have completed running all the above steps on the worker nodes. run the kube join command that you got from the master in all the worker nodes

kubeadm join --token 6065d6.90ab98e756bd01b3 172.31.123.145:6443 --discovery-token-ca-cert-hash sha256:611b3df6515064293e1a8c7583a64f9d72e660c68011d981d6759b7017311c7b

Then check the kubectl get nodes command to check the nodes connected

[root@nikhitkumar4 user]# kubectl get nodes
NAME                           STATUS     ROLES     AGE       VERSION
nikhitkumar4.server.com   Ready      master    16d       v1.9.2
nikhitkumar5.server.com   NotReady       16d       v1.9.2

We have completely set up our kubernetes multinode cluster

Leave a comment