How to setup a Kubernetes cluster

Rate this item
(0 votes)

The initial setup consists of a remote server running KVM in which three virtual machines were installed using Ubuntu 16.04. Each virtual machine has one network interface bridged to a physical network interface on the remote server, so that each VM is using a different interface of the server and IP addresses were assigned accordingly.

At the end of this tutorial, you will have a kubernetes cluster that consist of one Kubernetes master and two Kubernetes nodes.

Docker installation

First, let's install updates, dependencies and docker:

sudo apt update
sudo apt upgrade
sudo apt install apt-transport-https # already installed
sudo apt install

Now, we can start docker and enable it to start during the system boot:

sudo systemctl start docker
sudo systemctl enable docker

Kubernetes installation

Before the installation, we need to add the key:

sudo curl -s | sudo apt-key add -

To create the apt repository for Kubernetes, we open a file:

sudo nano /etc/apt/sources.list.d/kubernetes.list

and add the following line into it and close the file:

deb kubernetes-xenial main

Time to update and install kebernetes:

sudo apt update
sudo apt install kubelet kubeadm kubectl kubernetes-cni

Kubernetes master

To initialise Kubernetes cluster to run as master, execute the below command:

sudo kubeadm init --pod-network-cidr

If you receive this error:

[preflight] Some fatal errors occurred:
[ERROR Swap]: running with swap on is not supported. Please disable swap
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

You will need to disable the swap:

sudo nano /etc/fstab # comment swap to disable permanently
sudo swapoff -a

After the initialisation, you will see something like this:

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:

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

kubeadm join --token de5fen.6y2w4x7shlyhnfyf8 --discovery-token-ca-cert-hash sha256:2a9dfacf654eba7d374b8dfac0028d6a094c550c67bc084f1efcc1f4301ca656

To complete the setup:

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

Execute below commands on master node to apply network settings:

sudo kubectl apply -f
sudo kubectl apply -f

Now, check all pods:

sudo kubectl get pods --all-namespaces

Kubernetes node

First of all, follow: Docker installation and Kubernetes installation. Then:

kubeadm join --token de5fen.6y2w4x7shlyhnfyf8 --discovery-token-ca-cert-hash sha256:2a9dfacf654eba7d374b8dfac0028d6a094c550c67bc084f1efcc1f4301ca656

Go back to Master and check:

kubectl get nodes

k8-master Ready master 17h v1.11.0
k8-node1 Ready  37s v1.11.0
k8-node2 Ready  29s v1.11.0


3421 Last modified on Monday, 20 July 2020 14:44
More in this category:
Luis Sequeira

Luis Sequeira is an IT professional with experience in cloud environments, quality of service and network traffic analysis, who loves looking for solutions to engineering challenges, share knowledge. At work, the main challenge is to integrate different network and software technologies to provide solution in a wide range of areas, e.g., virtual network functions, machine learning, autonomous driving, robotics and augmented reality.


Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.