Install k3s cluster into Alpine Linux

I'll use Alpine Linux as it is a so light distribution.

My setup is:

192.168.1.100 master
192.168.1.101 node1
192.168.1.102 node2

Into master, let's install requirements, install the master node and get the token:

apk add curl
curl -sfL https://get.k3s.io | sh -
cat /var/lib/rancher/k3s/server/node-token

Into each one of the nodes:

apk add curl
k3s_token="<your_master_token_here>"
curl -sfL https://get.k3s.io | K3S_URL=https://master:6443 K3S_TOKEN=${k3s_token} sh -

Into the master again, check we see the nodes and config them as workers and disable the master node to run pods:

kubectl get nodes
kubectl label node node1 node-role.kubernetes.io/worker=worker
kubectl label node node2 node-role.kubernetes.io/worker=worker
kubectl taint --overwrite node master node-role.kubernetes.io/master=true:NoSchedule

It's done :)

If you want to run kubectl from another PC, install kubectl into your PC:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/sbin/

And then, copy the file /etc/rancher/k3s/k3s.yaml from your master into your ~/.kube/config PC.

You are ready! Test it from your PC:

costales@T410:~$ kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   46m   v1.23.6+k3s1
node2    Ready    worker                 38m   v1.23.6+k3s1
node1    Ready    worker                 38m   v1.23.6+k3s1
costales@T410:~$ 

Not happy with k3s? Uninstall it with this command:

k3s-uninstall.sh