Jul 20, 2024

Running Kubernetes

I recently decided it is time to learn Kubernetes. Here is the follow-up.

The best way to learn a new technology is to go hands-on with it. The official tutorial recommends using minikube to get started, as it lets you quickly setup a local cluster to play with. However, after experimenting with it for a few days, I decided I wanted more: a REAL cluster, with REAL machines, so I could feel like a TRUE hacker who runs their own homelab (sigh).

With the decision made, it was time to go shopping.

Procuring hardware

I found some decent options on Facebook Marketplace in my area. Roughly £100 for a Dell Optiplex 5040 SFF, with a quad core 5th-gen Core i5, with 8GB of RAM and 256GB of storage. The machine was in excellent condition, and I was happy with the price. I procured two of them, installed Ubuntu, appropriately named them server-1 and server-2. I have learnt that hardware is cattle, not pets — I should not get attached.

I also setup Tailscale on them, which meant I could reach these machines from anywhere securely. If I get any useful services running on my cluster, it would be easy to connect to them without exposing my machines to the internet directly. Tailscale is great, I can’t recommend it enough.

Now that I had some real machines, it was time to get Kubernetes running on them.

Creating a cluster

With the machines ready to go, it was time to setup a cluster by installing Kubernetes.

I was surprised to learn that I couldn’t just sudo apt install kubernetes. Instead, I had to choose one of the several kubernetes distributions. While you can run the upstream version directly, it is usually easier to go with something like MicroK8s, or K3s. You could even run minikube on a multi-node cluster, but I decided to go with MicroK8s instead.

The installation process was fairly easy. The first machine became the master, and I ran microk8s add-node on the second machine to make it a worker. Apparently it is not a good idea to have an even number of master nodes.

  ~ kubectl get nodes
NAME       STATUS
server-1   Ready
server-2   Ready

Even though I setup only two machines, I realised the value of automated installations for operating systems. Setting up SSH keys, networking, Docker, and a whole bunch of other configs is tedious. While researching better ways to do this, I also came across NixOS. Definitely going to explore that in the future.

Ansible is another tool that could help me here, as it can be used to setup playbooks to automate all of those steps.

That’s it for this post. I’ll continue documenting my adventures with Kubernetes, so stay tuned.