rasti.hil@hilandco.com +41 79 367-9677

Search This Blog

K3s on MacBook M1 with multipass

Setting Up a Kubernetes Cluster with Multipass and K3s

In this tutorial, we will walk through the process of setting up a lightweight Kubernetes cluster using Multipass and K3s. Multipass is a tool that allows you to create and manage virtual machines on your local machine, and K3s is a lightweight Kubernetes distribution that is designed for resource-constrained environments. This combination makes it easy to create a local Kubernetes playground for development and testing purposes.

Prerequisites

Before you begin, make sure you have the following prerequisites installed on your machine:

  • Homebrew : A package manager for macOS.

Installation

To get started, open your terminal and execute the following commands to install Multipass using Homebrew:


brew install --cask multipass

Creating the Kubernetes Master Node

Let’s start by creating the Kubernetes master node using Multipass. Run the following commands to launch the VM and set its resources:


multipass launch --name k3s --mem 4G --disk 10G

After the VM is launched, access its shell using:


multipass shell k3s

Inside the VM’s shell, run the following commands to install K3s:


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

Retrieve the Kubernetes token and the VM’s IP address:


mytoken=$(multipass exec k3s sudo cat /var/lib/rancher/k3s/server/node-token)
myip=$(multipass info k3s | grep -i ip | tr -d ' ') ; myip=${myip/IPv4:/} ; echo $myip

Creating Worker Nodes

Next, let’s create two Kubernetes worker nodes named k3s-w1 and k3s-w2 with the following commands:


multipass launch --name k3s-w1 --mem 2G --disk 10G
multipass launch --name k3s-w2 --mem 2G --disk 10G

Run the following commands to install K3s on the worker nodes:


multipass exec k3s-w1 -- bash -c "curl -sfL https://get.k3s.io | K3S_URL=https://$myip:6443 K3S_TOKEN=$mytoken sh -"
multipass exec k3s-w2 -- bash -c "curl -sfL https://get.k3s.io | K3S_URL=https://$myip:6443 K3S_TOKEN=$mytoken sh -"

Verifying the Cluster

Now that the cluster is set up, let’s verify it by checking the nodes:


multipass exec k3s -- bash -c "sudo kubectl get nodes"

Cleanup

After you’ve finished working with the Kubernetes cluster, you can delete the VMs using the following commands:


multipass delete k3s k3s-w1 k3s-w2
multipass purge

Conclusion

In this tutorial, we’ve learned how to set up a Kubernetes cluster using Multipass and K3s. This lightweight setup is ideal for local development and testing purposes. It allows you to experiment with Kubernetes concepts without the need for a cloud-based environment. Remember that this setup is not suitable for production environments, but it’s a great tool for learning and exploration.