or any other device really…
This is a quick tutorial on how to get your own Kubernetes cluster up and running in no time. This is basically the procedure I use every time I want to add a new cluster or when I have to rebuild one for any reason.
If you already have a Linux machine setup, you may jump to “3. K3S installation”
# 1. Install Debian / Raspbian
# 2. Setup cgroup thingy if this is a Pi
sudo nano /boot/cmdline.txt
# Add cgroup_memory=1 cgroup_enable=memory
# 3. # Download and install K3S
curl -sfL https://get.k3s.io --output get-k3s.sh
chmod +x get-k3s.sh
./get-k3s.sh --disable=traefik
# 4. Install Lens: https://github.com/MuhammedKalkan/OpenLens/releases
# 5. Connect with Lens or any other client, using the credentials and replacing 127.0.0.1 by your IP address
sudo ip a # To find your IP
sudo cat /etc/rancher/k3s/k3s.yaml # To retrieve default admin credentials
First, you should choose some hardware for your cluster. I personally started with a Raspberry Pi as they are were pretty inexpensive little machines. You can really use any device, though the steps might vary slightly.
In this tutorial I will cover the Raspberry Pi 4B. I would advise you choose the 4GB or 8GB models to host your services, but this should work with older models or with less memory. You’ll also need a USB power supply and a MicroSD, usual things with the Pi.
I will also cover a generic x64 platform matching my current setup at home, with my Mele Quieter 3Q. But any old computer would do the trick as well!
sudo nano /boot/cmdline.txt
cgroup_memory=1 cgroup_enable=memory
Your command line should look similar to:
console=tty1 root=PARTUUID=266982c5-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait cgroup_memory=1 cgroup_enable=memory
Now the good part, let’s install Kubernetes. I tried multiple distributions, but I find K3S to be the easiest to setup and use.
curl -sfL https://get.k3s.io --output get-k3s.sh
chmod +x get-k3s.sh
./get-k3s.sh --disable=traefik
At this point, your cluster is installed, up and running. Yes, that simple.
I use the --disable=traefik
command line parameter because I handle my own reverse proxy installation. Traefik is a reverse proxy to allow incoming HTTP/HTTPS traffic to reach your services running in the cluster. You can use the built-in one removing this parameter, or read my next articles to understand my setup 🙂
All additional options can be found on K3S website: https://rancher.com/docs/k3s/latest/en/quick-start/
But here are the ones I use the most:
INSTALL_K3S_VERSION=v1.21.5+k3s2 ./get-k3s.sh --disable=traefik
./get-k3s.sh --disable=traefik --tls-san 192.168.1.2
Then you’ll need to interact with your cluster. If you live only by CLI, first reconsider using graphical tools, it can help you learn Kubernetes faster, but you can use the official command line tool kubectl (have fun pronouncing this one, I personally say “CubeControl”).
You can download kubectl here: https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/
Else, I would strongly suggest using a graphical tool to help you understand Kubernetes concepts faster and navigating your cluster more easily. If find that Lens is the perfect tool for that: https://k8slens.dev
It is open source, but as the time of writing this article, they recently made it so you have to create a cloud account to use the software. Fortunately, since the software is open source, some people rebuilt it as OpenLens without those limitations: https://github.com/MuhammedKalkan/OpenLens
As they are basically the same, I will refer to both as Lens, even if I personally use OpenLens.
On the machine with K3S installed, run this command line to retrieve the default admin credentials:
sudo cat /etc/rancher/k3s/k3s.yaml
You now have to add those credentials to Lens or kubectl.
k3s.yaml
file, replacing the 127.0.0.1
reference by the LAN IP of your machine, for example 192.168.1.134
%USERPROFILE%\.kube\config
, or create the file and put the content of k3s.yaml
in it.
Anyway, make sure to replace the 127.0.0.1
reference by the LAN IP address of the machine running K3S.
At this point, either by running kubectl command or by clicking on your cluster in Lens, you should be able to explore your brand new empty cluster!
Now that this - not so big - step is behind us, the following articles will focus on what to install in your cluster.
Many will cite Minikube, I personally find it overrated and complex to use. Rancher, developer of K3S, recently released Rancher Desktop: https://rancherdesktop.io
It is targeted as a drop-in replacement for Docker Desktop, with built-in container management (Docker and alternative CLIs) and a Kubernetes cluster (it uses K3S).
Just install it, and you’re good to go with your cluster!
K3S got you covered, once KS is installed on your master node:
cat /var/lib/rancher/k3s/server/node-token
K3S_URL=https://:6443 K3S_TOKEN= ./get-k3s.sh --disable=traefik