Kubernetes homelab - Learning by doing, Part 2: Installation

Sacha Thommet - Oct 17 - - Dev Community

In this part, I'll walk you through the (few) installation steps for the cluster.

Operating system

I opted for Ubuntu Server since I'm already familiar with Ubuntu because I'm using it on my desktop computer.

Maybe in the future I will try others systems, like Talos which is designed for Kubernetes - secure, immutable, and minimal.

Kubernetes Distribution

Given that MicroK8s is developed by Canonical, the same team behind Ubuntu, I naturally choose it.

It supports all the features that I need:

  • It can run on a single node without requiring high availability (HA).
  • Yet it also supports HA, I can add a third node in the future.
  • Easy to install & to update.

Installation

Installing MicroK8s was super simple by following the official guide available here.

Prerequisites

As with any installation of this kind, the first step is to ensure your system meets the requirements.

  • At least Ubuntu 16.04 LTS, or newer to run the commands (or another operating system which supports snapd - see the snapd documentation).
  • MicroK8s runs in as little as 540MB of memory, but to accommodate workloads, Canonical recommend a system with at least 20G of disk space and 4G of memory.
  • An internet connection

Install

Run these commands on every node, in my case server1 and server2.

# install microk8s
sudo snap install microk8s --classic --channel=<version>

# Add your current user to the microk8s group
# and gain access to the .kube directory (where some of the k8s configuration goes on) 
sudo usermod -a -G microk8s $USER
mkdir -p ~/.kube
chmod 0700 ~/.kube
Enter fullscreen mode Exit fullscreen mode

Then, create a cluster by adding server2 as a worker to the server1 master node.

# On the master node (server1)
microk8s add-node

# Then from the node you wish to join to this cluster, run the command displayed by the command above, like:

# Join as a worker, not running the Kubernetes control plane
microk8s join <server1_ip>:25000/92b2db237428470dc4fcfc4ebbd9dc81/2c0cb3284b05 --worker

# Finally, from the master node, run to see the nodes in the cluster:
microk8s kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

And voila, it's that simple!

. . . . .