Kubernetes (k3s)

Written March 27, 2022

k3s claims to be a very light weight, production-ready kubernetes solution compatible with x86-64 and ARM.

Security tip: Never curl ... | bash, despite what their Quick-Start guide says. Trust no one.

Install the k3s binary

https://github.com/k3s-io/k3s/releases (As of the time of this writing, v1.23.4+k3s1 is the latest)

K3S_VERSION="v1.23.4+k3s1"

archSuffix=""
if test "$(uname -m)" = "aarch64"
then
    archSuffix="-arm64"
fi
wget -q "https://github.com/k3s-io/k3s/releases/download/${K3S_VERSION}/k3s${archSuffix}" -O ~/.local/bin/k3s
chmod u+x ~/.local/bin/k3s
k3s --version

Start the Kubernetes control plane

sudo $(which k3s) server

Merge the kubeconfig

sudo $(which k3s) kubectl config rename-context default k3s
sudo $(which k3s) kubectl config view --raw > /tmp/k3s.yaml
if test -f ~/.kube/config
then
    cp -p ~/.kube/config ~/.kube/config.bak
    KUBECONFIG=~/.kube/config.bak:/tmp/k3s.yaml kubectl config view --flatten > ~/.kube/config
else
    mkdir ~/.kube
    install -m 400 /tmp/k3s.yaml ~/.kube/config
fi

Test it

kubectl config use-context k3s
kubectl version --short
kubectl get namespaces

Cleanup

sudo rm -R /var/lib/rancher/k3s/
sudo rm -R /etc/rancher/
sudo rm -R /var/lib/kubelet
sudo rm -R /var/lib/cni