Oct 3, 2022

Start K3s with Multipass

Prerequisite: You need to have a working multipass, and preferably a Linux-based host. (I'm using WSL 😎 )

Then follow the steps to create the virtual machines and follow by create the k3s cluster. K3s promises to be a lightweight K8s

Here are the tools used and the description.

Tools Description
Multipass It's a system that orchestrates the creation, management and maintenance of virtual machines and associated Ubuntu images to siplify development.
K3s K3s is a certified Kubernetes distribution designed for production workloads in unattended, resource-constrained, remote locations or inside IoT appliances.

First, we need 1 master node (kmaster) and 2 worker nodes (kworker1 and kworker2).

$ multipass launch --name kmaster
$ multipass launch --name kworker1
$ multipass launch --name kworker2

Second, we need to create the K3s cluster. 

$ multipass exec kmaster -- /bin/bash -c "curl -sfL https://get.k3s.io | sh -"

$ K3S_NODEIP_MASTER="https://kmaster.mshome.net:6443"

$ K3S_TOKEN="$(multipass exec kmaster -- /bin/bash -c "sudo cat /var/lib/rancher/k3s/server/node-token")"

$ multipass exec kworker1 -- /bin/bash -c "curl -sfL https://get.k3s.io | K3S_TOKEN=${K3S_TOKEN} K3S_URL=${K3S_NODEIP_MASTER} sh -"

$ multipass exec kmuworker2 -- /bin/bash -c "curl -sfL https://get.k3s.io | K3S_TOKEN=${K3S_TOKEN} K3S_URL=${K3S_NODEIP_MASTER} sh -"

Last, let's examine the status.

$ multipass list

kmaster    Running           172.22.64.124    Ubuntu 22.04 LTS
                             10.42.0.0
                             10.42.0.1
kworker1   Running           172.22.70.140    Ubuntu 22.04 LTS
                             10.42.1.0
                             10.42.1.1
kworker2   Running           172.22.65.28     Ubuntu 22.04 LTS
                             10.42.2.0
                             10.42.2.1

And check if everything is working.

$ multipass exec kmaster sudo kubectl get nodes

NAME       STATUS   ROLES                  AGE   VERSION
kmaster    Ready    control-plane,master   19m   v1.24.6+k3s1
kworker1   Ready    <none>                 80s   v1.24.6+k3s1
kworker2   Ready    <none>                 46s   v1.24.6+k3s1

 

kubectl get nodes

In less than 10 min, we just setup 1 master and 2 worker nodes. Let's continue on other configuration at K3S Configuration Options.


Links: