k3d - first contact

While it’s very convenient to develop locally with docker compose there is often this gap to Kubernetes production deployment we want to close.

This post describes how we prepared to move from a small docker-compose setup for development closer to K8s with k3d.

K3s - Lightweight Kubernetes

k3d - is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker

If you already have Docker Desktop up and running you might want to check Eventually - Taking Kubernetes for a Spin.

Install k3d with home-brew

Lucky us a Homebrew Formulae k3d exists…check Installation for other options.

$ brew install k3d
🍺  /usr/local/Cellar/k3d/4.4.4: 9 files, 16.8MB

You can easily verify the installation with k3d version:

k3d version v4.4.4
k3s version latest (default)

Sandbox cluster

We need a cluster with access to our internal Docker registry for maximum fun!

  • port 9051 exposed (the actual application) and
  • a local directory to configure access to the internal Docker registry.
k3d cluster create \
    --volume "$(PWD)/registries.yml:/etc/rancher/k3s/registries.yaml" \
    --port 9051:9051@loadbalancer sandbox
INFO[0020] Pulling image 'docker.io/rancher/k3d-proxy:v4.4.4'
INFO[0025] Starting cluster ‘sandbox’
INFO[0036] You can now use it like this:
kubectl config use-context k3d-sandbox
kubectl cluster-info

Get up to speed with

k3d kubeconfig get banner-generator > kube_config_cluster.yml
export KUBECONFIG=$(PWD)/kube_config_cluster.yml

Tip: Check ShellHacks - Kubectl: Switch Context - Kubernetes for more context fun…

By now you should be ready to enter the sandbox - just a quick check 😇

kubectl config current-context

Looks good, let’s run the famous hello-world:

cat << EOF | kubectl apply -f -
apiVersion: batch/v1
kind: Job
  name: hello-world
        - name: hello-world
          image: hello-world
      restartPolicy: Never

Run kubectl logs --tail 30 --selector=job-name=hello-world to check the output. Nice

Just grabbing some toys (Lens, a Spring Boot App, Gradle, jib, Jenkins, … ). I’ll keep you in the loop…

(bonus) The internal docker registry configuration

Just because it took me so long to get the subtleties right

      - "https://sandbox.internal"
      ca_file: "/etc/ssl/certs/sandbox.pem"
      username: registry
      password: ********

Please make sure you use the same keys in mirrors and configs (sandbox.internal in our case)!

Meanwhile - happy kubernauting 🤖…

Photo by Timelab Pro on Unsplash