K3s

Using a local cluster is very handy to get started with Kubernetes, or to test things quickly. In this example, we’ll use K3s, a lightweight Kubernetes distribution. K3s is a certified distribution, well-suited for IoT, Edge computing, and which works well with huge servers.

We’ll use Multipass, which is a convenient tool to launch Ubuntu virtual machines on Mac, Linux, or Windows, and install k3s on these VMs.

ℹ️
Please refer to Multipass installation doc to install it on your environment

We’ll only create a single node cluster, it’ll be enough to get started.

Pre-requisite

On your local machine, install kubectl. It’s the essential tool for communicating with a Kubernetes cluster from the command line.

Creating an Ubuntu VM

Once you’ve installed Multipass, create an Ubuntu 24.04 virtual machine named k3s with 2G of memory allocated. This process should take a few tens of seconds.

multipass launch --name k3s --memory 2G

Then get the IP address of the newly created VM.

IP=$(multipass info k3s | grep IP | awk '{print $2}')

Installing k3s

Run the following command to install k3s the VM. This process should also take a few tens of seconds.

multipass exec k3s -- bash -c "curl -sfL https://get.k3s.io | sh -"
ℹ️
The command curl -sfL https://get.k3s.io | sh -, used to install k3s comes from the official k3s documentation

Getting the kubeconfig file

Retrieve the configuration file generated during Kubernetes installation on your local machine:

multipass exec k3s sudo cat /etc/rancher/k3s/k3s.yaml > k3s.cfg.tmp

In this file, replace the local IP address (127.0.0.1) with the IP address of the VM you created. This IP address should be in the $IP environment variable.

cat k3s.cfg.tmp | sed "s/127.0.0.1/$IP/" > k3s.cfg

Then set the KUBECONFIG environment variable to point to the previously retrieved configuration file:

export KUBECONFIG=$PWD/k3s.cfg
ℹ️
This environment variable configures the kubectl binary, so it can communicate with the cluster.

You can now communicate with the cluster’s API Server.

List of the cluster’s node (only one in this example):

kubectl get nodes

List of the Pods running in the cluster:

kubectl get pods -A