In this guide, I’ll take you through the steps to install and set up a working 3 node Kubernetes Cluster on Ubuntu 18.04 Bionic Beaver Linux. Kubernetes is an open-source container-orchestration system used for automating deployment, management, and scaling of containerized applications.

Kubernetes on Ubuntu 18.04 – System Diagram

This setup is based on the following diagram:

Let’s configure system hostnames before we can proceed to next steps:

On Master Node:

Set hostname like below:

$ sudo hostnamectl set-hostname k8s-master

On Worker Node 01:

Set the hostname using hostamectl command line tool.

$ sudo hostnamectl set-hostname k8s-node-01

On Worker Node 02:

Also set hostname for Kubernetes worker node 02.

$ sudo hostnamectl set-hostname k8s-node-02

Once correct hostname has been configured on each host, populate on each node with the values configured.

All commands that will be executed on this section are meant to be run on the master node. Don’t execute any of the commands on Kubernetes worker nodes. Kubernetes Master components provide the cluster’s control plane – API Server, Scheduler, Controller Manager. They make global decisions about the cluster e.g scheduling and detecting and responding to cluster events.

Add Kubernetes repository

As of this writing, there is no official repository for Ubuntu 18.04, we will add a repository for Ubuntu 16.04. I tested it. All packages and dependencies should install fine. I’ll update this article when a repo for Ubuntu 18.04 is available.

If all goes well, you should get a success message with the instructions of what to do next:

---
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 192.168.2.2:6443 --token 9y4vc8.h7jdjle1xdovrd0z --discovery-token-ca-cert-hash sha256:cff9d1444a56b24b4a8839ff3330ab7177065c90753ef3e4e614566695db273c

Deploy Weave Net POD Network to the Cluster ( Run as normal user)

Weave Net creates a virtual network that connects Docker containers across multiple hosts and enables their automatic discovery. Services provided by application containers on the Weave network can be exposed to the outside world, regardless of where they are running.

Weave Net can be installed onto your CNI-enabled Kubernetes cluster with a single command:

Setup Kubernetes Worker Nodes

When Kubernetes cluster has been initialized and the master node is online, start Worker Nodes configuration. A node is a worker machine in Kubernetes, it may be a VM or physical machine. Each node is managed by the master and has the services necessary to run pods – docker, kubelet, kube-proxy

Step 1: Ensure Docker is installed (covered)

Step 2: Add Kubernetes repository ( covered)

Ensure that repository for Kubenetes packages is added to the system. Refer ^^

Step 3: Install Kubenetes components

Once you’ve added Kubernetes repository, install components using:

sudo apt install kubelet kubeadm kubectl kubernetes-cni

Step 4: Join the Node to the Cluster:

Use the join command given after initializing Kubernetes cluster. E.g

kubeadm join 192.168.2.2:6443 --token 9y4vc8.h7jdjle1xdovrd0z \
--discovery-token-ca-cert-hash sha256:cff9d1444a56b24b4a8839ff3330ab7177065c90753ef3e4e614566695db273c
---
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "k8s-node-02" as an annotation
This node has joined the cluster:
* Certificate signing request was sent to master and a response
was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the master to see this node join the cluster.

With the deployment created, we can use kubectl to create a service which exposes the Pods on a particular port. An alternative method is defining a Service object with YAML. Below is our service definition.