DEV Community

Vignesh Muthukumaran
Vignesh Muthukumaran

Posted on

Setup a k3s Cluster at home quickly

I was setting up a new Fedora Server VM over the weekend and wanted to use it as a kubernetes cluster to run my containerized workloads. I usually install docker and docker-compose and get on with my work. But I wanted to set up a k8s cluster for fun. When looking up online I found a quick and easy way to set it up.

Why k3s over k8s?

Rather than going with a full-blown k8s cluster with multiple VMs, I went with a single node k3s setup. k3s is a lightweight k8s, it has a smaller footprint and is great for a home lab.

I would encourage you to check out their docs for more info based on your requirements, but the gist is as follows.

Requirements

The minimum hardware requirement is

Spec Min Recommended
CPU 1 core 2 core
RAM 512 MB 1 GB  

I am running this on a Fedora Server VM with 4 cores and 8 GB of RAM, so well above the recommended settings.

Installation

The command to install is,

curl -sfL https://get.k3s.io | sh -
Enter fullscreen mode Exit fullscreen mode

It will ask for the sudo password. Have a look at the script before running it at Installation Script. Also, they have a lot of options to customize the components installed. Check out the full list at Config Options.

Verify the install

If everything goes well, you should be able to check the service through systemctl.

$ systemctl status k3s
● k3s.service - Lightweight Kubernetes
     Loaded: loaded (/etc/systemd/system/k3s.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: active (running) since Sun 2024-07-14 18:47:30 IST; 21min ago
       Docs: https://k3s.io
Enter fullscreen mode Exit fullscreen mode

Check the default k3s objects

Running the following command gives you all the k3s objects deployed.

$ sudo kubectl get all -n kube-system
NAME                                         READY   STATUS    RESTARTS   AGE
pod/coredns-6799fbcd5-svqqf                  1/1     Running   0          26m
pod/local-path-provisioner-6f5d79df6-d8h5g   1/1     Running   0          26m
pod/metrics-server-54fd9b65b-5xxq4           0/1     Running   0          26m

NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE
service/kube-dns         ClusterIP   10.43.0.10 <none>        53/UDP,53/TCP,9153/TCP   26m
service/metrics-server   ClusterIP   10.43.198.179 <none>        443/TCP                  26m

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/coredns                  1/1     1            1           26m
deployment.apps/local-path-provisioner   1/1     1            1           26m
deployment.apps/metrics-server           0/1     1            0           26m

NAME                                               DESIRED   CURRENT   READY   AGE
replicaset.apps/coredns-6799fbcd5                  1         1         1       26m
replicaset.apps/local-path-provisioner-6f5d79df6   1         1         1       26m
replicaset.apps/metrics-server-54fd9b65b           1         1         0       26m

Enter fullscreen mode Exit fullscreen mode

Configuring k3s

Create and edit the following file to configure the k3s setup.

sudo vi /etc/rancher/k3s/config.yaml
Enter fullscreen mode Exit fullscreen mode

Check out all the available config at k3s Config.

Post, the creation/updation of the config file, restart using systemctl.

sudo systemctl restart k3s
Enter fullscreen mode Exit fullscreen mode

Stopping k3s

Just use systemctl to stop the service.

sudo systemctl stop k3s
Enter fullscreen mode Exit fullscreen mode

Unintalling k3s

Uninstalling is also a breeze with k3s, as it generates an uninstall script as soon as you install k3s at /usr/local/bin/k3s-uninstall.sh.

Just run the script to uninstall.

/usr/local/bin/k3s-uninstall.sh
Enter fullscreen mode Exit fullscreen mode

Post uninstall and check the status with systemctl.

systemctl status k3s
Enter fullscreen mode Exit fullscreen mode

Originally published at vignesh.page.
Please comment any workloads you have for a k3s cluster at home.

Top comments (0)