Prepare VMs by Multipass

multipass find
multipass launch -c 1 -m 1G -d 5G -n k3s-master 20.04
multipass launch -c 1 -m 2G -d 10G -n k3s-node01 20.04
multipass launch -c 1 -m 2G -d 10G -n k3s-node02 20.04

multipass list
multipass info k3s-node01

Install K3s

install master

multipass exec k3s-master -- bash -c "curl -sfL | sh -"

# instead use shell:
# multipass shell k3s-master
ubuntu@k3s-master:~$ curl -sfL | sh -
[INFO]  Finding release for channel stable
[INFO]  Using v1.21.4+k3s1 as release
[INFO]  Downloading hash
[INFO]  Downloading binary
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/
[INFO]  Creating uninstall script /usr/local/bin/
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink /etc/systemd/system/ → /etc/systemd/system/k3s.service.
[INFO]  systemd: Starting k3s

a token is stored in master:

sudo cat /var/lib/rancher/k3s/server/node-token

TOKEN=$(multipass exec k3s-master sudo cat /var/lib/rancher/k3s/server/node-token)
IP=$(multipass info k3s-master | grep IPv4 | awk '{print $2}')

install agents

multipass exec k3s-node01 -- bash -c "curl -sfL | K3S_URL=\"https://$IP:6443\" K3S_TOKEN=\"$TOKEN\" sh -"
multipass exec k3s-node02 -- bash -c "curl -sfL | K3S_URL=\"https://$IP:6443\" K3S_TOKEN=\"$TOKEN\" sh -"

use k8s cluster

 __workspace__ multipass exec k3s-master -- bash
ubuntu@k3s-master:~$ sudo kubectl get nodes
NAME         STATUS   ROLES                  AGE   VERSION
k3s-node01   Ready    <none>                 14m   v1.21.4+k3s1
k3s-master   Ready    control-plane,master   29m   v1.21.4+k3s1
k3s-node02   Ready    <none>                 90s   v1.21.4+k3s1

access from host

multipass mount tmp k3s-master
multipass mount tmp k3s-master:/home/tmp

Notice: Need to set privacy settings

Then copy /etc/rancher/k3s/k3s.yaml, and save to ~/.kube/config, replace ip address to the master node ip.

kubectl get pods --all-namespaces


install dashboard


to access, use kubectl in host and proxy.