Kubernetes (k3d)

Written Sept 5, 2022

k3d is k3s wrapped in a container. What makes it desirable over k3s, for me at least, is the isolation that comes with containers, so you don't need to worry about things during the install potentially interferring with your system or leaving extra cruft behind after uninstalling.

Prequisities

You need the docker daemon running. Sadly, k3d does not support nerdctl yet.

Install the k3d binary

https://github.com/k3d-io/k3d/releases (As of the time of this writing, v5.4.6 is the latest)

K3D_VERSION="v5.4.6"

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

Start the Kubernetes control plane

Whenever running things in containers, you need to declare your port mappings in advance, just like kind. This is if you use Node Ports. They fall in the range 30000-32767. I used 31337 just so I have a port available for testing later.

if test "${archSuffix}" = "arm64"
then
    archSuffix="-${archSuffix}"
else
    archSuffix=""
fi
k3d cluster create --k3s-arg "--disable=traefik@server:0" -i "rancher/k3s:v1.23.10-k3s1${archSuffix}" -p 31337:31337  # add more -p arguments if you need them

Notice I specified the kubernetes version. You can view the available image tags here. The docker tag names have replaced + sign in the git release tag with the - sign.

Running on podman

# start the podman service API
# TBD if this was required:
# sudo mount --make-rshared /
#
podman --log-level=info system service -t 0 unix://$HOME/.podman.sock &
#sudo ln -s unix://$HOME/.podman.sock /var/run/docker.sock
#sudo podman --log-level=info system service -t 0 unix:///var/run/docker.sock &
#sudo chgrp $(id -gn) /var/run/docker.sock
#sudo chmod g+rw /var/run/docker.sock

# sudo mount --make-rshared /
#export DOCKER_HOST=unix:$HOME/.podman.sock
#export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=$DOCKER_HOST
export DOCKER_SOCK=$HOME/.podman.sock
export DOCKER_HOST=unix://$HOME/.podman.sock

k3d registry create --default-network podman mycluster-registry


k3d cluster create --registry-use mycluster-registry --k3s-arg "--disable=traefik@server:0" -i "rancher/k3s:v1.23.10-k3s1${archSuffix}" -p 31337:31337

# shutdown k3d
k3d cluster delete
k3d registry delete mycluster-registry

# shutdown the podman service API
kill $(pgrep -f 'podman.* system service')

Test it

kubectl config current-context
kubectl version --short
kubectl get namespaces

Cleanup

k3d cluster delete