K3{S|D}— Smart Dynamic

K3s K3d

Lightweight —Simple —Easy — Secure — Production Ready

K3s by Rancher is the lightweight Linux distribution, designed for situations where compute resources may be limited, or where a smaller footprint of a Kubernetes solution is needed such as IoT and Edge devices. K3d is then the lightweight wrapper to run K3s and create multi-node K3s clusters with ease.

K3SD Smart Dynamic

K3s it now a CNCF sandbox project.

K3s — Indefinite options

How do you want to run k3s? On your laptop, on dedicated hardware, Raspberry Pi? In a VM? The options are unlimited.

K3s can be installed in places that you would have never dreamt would run K8s only a short while ago. K3s can even be deployed in an HA mode.

In our today’s blog post, we’re going to explore both options:

  • K3s — Single-node install
  • K3d — Multi-node install

K3S —Single Server Install

The fastest way to install K3s is on a single node. This provides with a single server that acts as both the control plane and a worker. This kind of installation is obviously not HA, but there are lots of places where a single node K8s cluster has value as long as whatever it’s managing isn’t mission-critical. There’s a path for recovery replacement of the nodes; we can find that it’s faster to bring up a new node and reinstall the manifests than it’s to manage an HA deployment.

a. Prerequisites
Before we check the setup, there are only two mandatory requirements: Docker and a Linux shell.

b. Download/Install the binaries
K3s is installed by pulling down an Install Script and piping it to “sh”.

curl -sfL https://get.k3s.io | sh -

Running a script directly from a URL is a significant security threat! Ensure to verify the script’s content before doing so.

Well, the shared script fetches K3s, installs it, creates sim-links, deploys a SystemD unit, and then starts it up. All in all, you’re up and running in under 10 seconds (excluding the download time).

K3s is an entirely self-contained binary; it includes containerd, its tools and kubectl. All in all it is less than 100 Mb.

c. Playing with K3s
Now, you can type “k3s kubectl cluster-info” or download the auth file and type “kubectl cluster-info” to get the same result.

K3s kubectl get nodes

We can see from the command’s output that we have a single node cluster running.

When the cluster first comes-up, it writes out a KubeConfig file to /etc/rancher/k3s/k3s.yaml.

This is the default location that k3s looks at when called as kubectl. If you copy it off of the host and change the address for the server, you can use this with kubectl on any other machine.

K3D —Multi-Node Install

It’s easy to question how K3s can be a production distribution of Kubernetes? How can such a small cluster be better than the alternatives, such as miniKube, microkates or other distros that are not fit for production?

Well, K3s is different as it is designed for multi-node HA operation in resource-constrained environments like IoT and the Edge, but it’s just as much at home in the DataCenter as it is in a fighter jet or wind farm. K3d comes to the picture to simplify the deployment of a K3s in a Highly Available mode.

A tarball is provided (250MB) for those looking to run k3s in a fully air-gap situation.

a. Download/Install the binaries
K3s can be installed with ease as a Highly Available cluster, using K3d. K3d is the lightweight wrapper to run k3s and to create K3s clusters.

Install K3d by grabbing the Install Script and piping it to “bash”, just as we did for K3s:

wget -q -O - https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash

b. Create a Multi-node Cluster
Let’s fire our first HA K3s cluster. In our case, we’re creating a cluster under the version 1.19.3.

b. Create a Multi-node Cluster
Let’s fire our first HA K3s cluster. In our case, we’re creating a cluster under the version 1.19.3.

k3d cluster create --servers 3 --image rancher/k3s:v1.19.3-k3s2

Let’s list the active clusters

k3d cluster list
K3d node list

Now, let’s get the new cluster’s connection details merged into our kubeConfig and check the running nodes:

kubectl config use-context k3d-k3s-default
kubectl get nodes

K3d does the magic by creating a fully available K3s cluster, with 3 running servers in addition to a dedicated load balancer node.

Cleanup time!

Uninstalling k3s

Uninstalling k3s is as fast as installing it. Every installation places an uninstall scripts into /usr/local/bin/k3s-uninstall.sh. Running this script removes all traces of k3s from the system like it never existed.

sh /usr/local/bin/k3s-uninstall.sh

Deleting the clusters created by K3d

The same goes for K3d by launching this command:

k3d cluster delete

&! to finish

K3s production distribution of Kubernetes that runs with the smallest possible footprint and well adapted for Edge and IoT devices, small enough to run even on a Raspberry PieZero. K3d helps running all of the K3s components in Megabytes of memory and managing Highly Available K3s clusters.

Author: Aymen Abdelwahed
Reviewer: Iko Saadhoff