If you don't have Multipass installed:
brew install --cask multipass
Create a VM with Ubuntu (ARM64 architecture, suitable for Apple Silicon):
multipass launch --name k3s-master --mem 4G --disk 20G
multipass launch --name k3s-worker --mem 8G --disk 20G --cpus 4
multipass shell k3s-master
curl -sfL https://get.k3s.io | sh -
Lets find out IP of the VM & k8s token so that we can spin up a new VM and add it to this cluster.
multipass exec k3s-master sudo cat /var/lib/rancher/k3s/server/node-token
multipass info k3s-master | grep -i ip
multipass shell k3s-worker
ubuntu@k3s-worker:~$ curl -sfL https://get.k3s.io | K3S_URL=https://192.168.64.28:6443 K3S_TOKEN="K10c..2::server:7757..f4" sh -
We can verify if the node is added correctly from k3s VM.
multipass exec k3s-master sudo kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3s-master Ready control-plane,master 2d23h v1.32.5+k3s1
k3s-worker Ready <none> 2d23h v1.32.5+k3s1
- To access kubectl from your macOS host:
Copy the kubeconfig file from the VM:
multipass exec k3s-master -- sudo cat /etc/rancher/k3s/k3s.yaml > kubeconfig
- Replace the internal IP (127.0.0.1) with your VM's IP:
Get the VM IP:
multipass info k3s-master
Edit kubeconfig and replace:
server: https://127.0.0.1:6443
with:
server: https://<YOUR_VM_IP>:6443
- Use it with kubectl:
export KUBECONFIG=$PWD/kubeconfig
kubectl get nodes