Skip to content
Kubernetes tools · Chapter 15 of 20 Day 13: Building and Throwing Away Clusters

Day 13: Building and Throwing Away Clusters

Goal: Create additional throwaway clusters with kind and k3d, get ports and images into them, save logs, describe clusters including a registry declaratively with ctlptl, and judge when Tilt, Skaffold or talosctl fit · Duration: approx. 70 min · Prerequisite: Day 12

Briefing

  • A cluster that you build in a minute and delete in seconds changes the way you work: you try out a chart, a policy, an upgrade without endangering the shared cluster.
  • kind (Kubernetes in Docker) starts each node as a Docker container with kubeadm inside. It is the tool of the Kubernetes developers themselves, and your lab has been running on it since Day 0.
  • k3d starts k3s in Docker: a lean Kubernetes distribution with a built-in ingress (Traefik), load balancer and metrics-server.
  • ctlptl (pronounced “cattle patrol”) describes a cluster and a local registry in one YAML file. One apply builds both and connects them.
  • All three change your kubeconfig. That is practical, and it is the most common trap of the day.
Tool Version Kubernetes inside
kind v0.33.0 v1.37.0
k3d v5.9.0 k3s v1.35.5 (default)
ctlptl v0.9.6 depends on the product (here kind)

Drill 1: A Second, Custom kind Cluster

A configuration file defines nodes and port forwards. extraPortMappings opens a port of the VM directly onto a port in the node container, here for a NodePort Service. The cluster is called wegwerf (throwaway):

mkdir -p ~/werkzeuge/tag13 && cd ~/werkzeuge/tag13
cat > wegwerf.yaml <<'EOF'
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: wegwerf
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30080
    hostPort: 8088
- role: worker
EOF
kubectl config current-context
kind create cluster --config wegwerf.yaml
kubectl config current-context

Expected (shortened):

kind-werkzeuge
…
You can now use your cluster with:

kubectl cluster-info --context kind-wegwerf

Thanks for using kind! 😊
kind-wegwerf

In the test, this took 67 seconds for two nodes (put time in front to measure it yourself). And your context now points to the new cluster without you asking for it. From here on, you work with --context so that no command accidentally lands in the lab. (With kubie from Day 3, it would also work in a separate shell.)

The new cluster does not know any images of your VM. Instead of a registry, kind load loads a local image directly into all nodes. You take the patched image from Day 11:

K="kubectl --context kind-wegwerf"
$K wait --for=condition=Ready nodes --all --timeout=120s
kind load docker-image laden/lieferung:1.30.6-gepatcht --name wegwerf
$K create deployment lieferung --image=laden/lieferung:1.30.6-gepatcht
$K create service nodeport lieferung --tcp=8080:8080 --node-port=30080
$K rollout status deploy/lieferung --timeout=90s

Expected (shortened):

node/wegwerf-control-plane condition met
node/wegwerf-worker condition met
Image: "laden/lieferung:1.30.6-gepatcht" with ID "sha256:3d419cbd…" not yet present on node "wegwerf-control-plane", loading...
deployment.apps/lieferung created
service/lieferung created
deployment "lieferung" successfully rolled out

create deployment sets no imagePullPolicy, and for a tag other than latest, IfNotPresent then applies. That is why the kubelet finds the loaded image without asking Docker Hub. Now from the VM via the mapped port:

curl -s http://localhost:8088/ | grep -o "<title>.*</title>"
docker ps --format "{{.Names}} {{.Ports}}" | grep wegwerf

Expected:

<title>Welcome to nginx!</title>
wegwerf-worker
wegwerf-control-plane 127.0.0.1:33739->6443/tcp, 0.0.0.0:8088->30080/tcp

If nothing comes back on the first attempt, wait a few seconds: the Service needs a moment until its rules are in place on all nodes. The Pod runs on the worker, and the request comes in through the control plane container; a NodePort applies on every node.

Before a throwaway cluster is gone, you save its logs if there are problems:

kind export logs ./kind-logs --name wegwerf
ls kind-logs kind-logs/wegwerf-control-plane
du -sh kind-logs

Expected:

./kind-logs
kind-logs:
docker-info.txt  kind-version.txt  wegwerf-control-plane  wegwerf-worker

kind-logs/wegwerf-control-plane:
alternatives.log  containerd.log  containers  images.log  inspect.json  journal.log  kubelet.log  kubernetes-version.txt  pods  serial.log
972K    kind-logs

Journal, kubelet, containerd and the logs of all Pods. Exactly what you attach to a bug report. Now get rid of it:

kind delete cluster --name wegwerf
kubectl config current-context

Expected:

Deleting cluster "wegwerf" ...
Deleted nodes: ["wegwerf-worker" "wegwerf-control-plane"]
error: current-context is not set

Deleting took just under four seconds. And the second trap: kind removes its context and leaves current-context empty. Every kubectl command now fails until you switch back:

kubectl config use-context kind-werkzeuge

Save your progress? Sign up for free

Drill 2: k3d

ARCH=$(dpkg --print-architecture)
curl -sLo /tmp/k3d https://github.com/k3d-io/k3d/releases/download/v5.9.0/k3d-linux-${ARCH}
sudo install /tmp/k3d /usr/local/bin/k3d
k3d version

Expected:

k3d version v5.9.0
k3s version v1.35.5-k3s1 (default)

k3d ships k3s 1.35, not 1.37 like your lab. For a different version, you specify an image (--image rancher/k3s:<version>). For quick tests, the default usually does not matter; for a test before an upgrade, it does.

This time, you prevent the context from switching right away. The cluster is called probe (test):

k3d cluster create probe --agents 1 -p "8089:80@loadbalancer" --kubeconfig-switch-context=false
k3d cluster list
kubectl --context k3d-probe get nodes
kubectl config current-context

Expected (shortened):

INFO[0059] You can now use it like this:
kubectl config use-context k3d-probe
kubectl cluster-info
NAME    SERVERS   AGENTS   LOADBALANCER
probe   1/1       1/1      true
NAME                 STATUS   ROLES           AGE   VERSION
k3d-probe-agent-0    Ready    <none>          11s   v1.35.5+k3s1
k3d-probe-server-0   Ready    control-plane   18s   v1.35.5+k3s1
kind-werkzeuge

-p "8089:80@loadbalancer" forwards port 8089 of the VM to port 80 of the k3d load balancer, and behind it Traefik waits as the ingress controller. So an Ingress works without further installation. The Deployment is called hallo (hello):

K="kubectl --context k3d-probe"
$K create deployment hallo --image=traefik/whoami:v1.11.0
$K expose deployment hallo --port 80
$K create ingress hallo --rule="/*=hallo:80"
$K -n kube-system wait --for=condition=complete job/helm-install-traefik --timeout=180s
$K -n kube-system rollout status deploy/traefik --timeout=120s
curl -s http://localhost:8089/ | head -3

Expected:

deployment.apps/hallo created
service/hallo exposed
ingress.networking.k8s.io/hallo created
job.batch/helm-install-traefik condition met
deployment "traefik" successfully rolled out
Hostname: hallo-7b59f847c7-h4n6h
IP: 127.0.0.1
IP: ::1

k3s installs Traefik after startup via a Helm Job. If you come with curl immediately after cluster create, you get no answer, hence the two wait lines. What else k3s brings along:

$K -n kube-system get pods --no-headers | awk '{print $1, $3}'

Expected:

coredns-8db54c48d-5gsh6 Running
helm-install-traefik-crd-kvlvs Completed
helm-install-traefik-wvdp7 Completed
local-path-provisioner-5d9d9885bc-4ccms Running
metrics-server-786d997795-bzddk Running
svclb-traefik-6632659e-jjq7h Running
svclb-traefik-6632659e-rtm7w Running
traefik-9bcdbbd9-ppzbg Running

metrics-server, storage and load balancer (svclb-…) are already there. What you installed by hand on Day 9 is built in here. And the memory footprint in comparison:

docker stats --no-stream --format "{{.Name}} {{.MemUsage}}" | grep -E "k3d|werkzeuge"

Expected (values will differ):

k3d-probe-serverlb 12.82MiB / 7.755GiB
k3d-probe-agent-0 168.4MiB / 7.755GiB
k3d-probe-server-0 725.1MiB / 7.755GiB
werkzeuge-worker 637.8MiB / 7.755GiB
werkzeuge-control-plane 1.332GiB / 7.755GiB
werkzeuge-worker2 596MiB / 7.755GiB

The k3d cluster needs about 0.9 GiB, the lab (with everything that has been running on it since Day 0) about 2.5 GiB. An empty kind cluster would be somewhere in between. You get images in as with kind (k3d image import <image> -c probe). Delete:

k3d cluster delete probe

Expected (shortened):

INFO[0010] Successfully deleted cluster probe!

Save your progress? Sign up for free

Drill 3: ctlptl, Cluster and Registry as a File

kind load copies an image into every node, again with every build. With a local registry, you push once, and the cluster pulls as in production. Setting this up by hand means: registry container, network, containerd configuration on every node, a ConfigMap. ctlptl turns this into one file. The cluster is called kind-mitregistry (with-registry):

V=0.9.6; A=$(uname -m | sed "s/aarch64/arm64/")
curl -sL https://github.com/tilt-dev/ctlptl/releases/download/v$V/ctlptl.$V.linux.$A.tar.gz | tar xz -C /tmp ctlptl
sudo install /tmp/ctlptl /usr/local/bin/
ctlptl version
cat > ctlptl.yaml <<'EOF'
apiVersion: ctlptl.dev/v1alpha1
kind: Registry
name: laden-registry
port: 5005
---
apiVersion: ctlptl.dev/v1alpha1
kind: Cluster
product: kind
name: kind-mitregistry
registry: laden-registry
EOF
ctlptl apply -f ctlptl.yaml
ctlptl get cluster
ctlptl get registry

Expected (shortened):

v0.9.6, built 2026-09-10
 🔌 Connected cluster kind-mitregistry to registry laden-registry at localhost:5005
 👐 Push images to the cluster like 'docker push localhost:5005/alpine'
cluster.ctlptl.dev/kind-mitregistry created
CURRENT   NAME               PRODUCT   AGE   REGISTRY
*         kind-mitregistry   kind      16s   localhost:5005
          kind-werkzeuge     kind      3h    none
          kubedrill          unknown   2h    none
NAME             HOST ADDRESS     CONTAINER ADDRESS   AGE
laden-registry   127.0.0.1:5005   172.17.0.2:5000     56s

With kind, the cluster name must start with kind-, because that is what the context is called. ctlptl get cluster lists all contexts of your kubeconfig, including the KubeDrill context from Day 3. The asterisk shows: ctlptl has switched the context, too. Now the way via the registry:

docker tag laden/lieferung:1.30.6-gepatcht localhost:5005/lieferung:1.30.6-gepatcht
docker push -q localhost:5005/lieferung:1.30.6-gepatcht
kubectl --context kind-mitregistry create deployment lieferung --image=localhost:5005/lieferung:1.30.6-gepatcht
kubectl --context kind-mitregistry rollout status deploy/lieferung --timeout=120s
kubectl --context kind-mitregistry -n kube-public get configmap local-registry-hosting -o jsonpath='{.data}{"\n"}'

Expected:

localhost:5005/lieferung:1.30.6-gepatcht
deployment.apps/lieferung created
deployment "lieferung" successfully rolled out
{"localRegistryHosting.v1":"host: localhost:5005\nhostFromClusterNetwork: laden-registry:5000\nhelp: https://github.com/tilt-dev/ctlptl\n"}

localhost:5005 works in the cluster just as on the VM, because ctlptl configured containerd on the nodes accordingly. The ConfigMap local-registry-hosting is a standard (KEP 1755) through which tools such as Tilt find the registry on their own. Tear it down, again with the file:

ctlptl delete -f ctlptl.yaml
kubectl config use-context kind-werkzeuge
docker ps --format "{{.Names}}" | grep -c registry

Expected:

Deleted nodes: ["mitregistry-control-plane"]
cluster.ctlptl.dev/kind-mitregistry deleted
Switched to context "kind-werkzeuge".
0

Cluster and registry are gone. The file stays and rebuilds both identically next time; it belongs in the project’s repo.

Save your progress? Sign up for free

Profiles: Tilt, Skaffold, talosctl

You do not install these three today. They are the next steps, depending on what you are building.

Tilt (v0.37.9, Apache 2.0) watches your source code, builds the image on every change, pushes it into the cluster (via the registry from Drill 3) and shows the logs of all services in one UI. The control file is a Tiltfile (Starlark, similar to Python). It fits teams that develop several services locally at the same time. ctlptl comes from the same team.

Skaffold (v2.25.0, Google, Apache 2.0) does the same core job, building and rolling out on every change, with a focus on pipelines: skaffold dev locally, skaffold run and skaffold render in CI. The control file is skaffold.yaml. It fits when the same description should apply locally and in the pipeline.

talosctl (v1.14.7) is the command line for Talos Linux, an operating system only for Kubernetes: no SSH, no shell, managed through an API. Like kind, talosctl cluster create builds a cluster from containers, but with real Talos inside. It fits when your production cluster runs on Talos and you want to test the same thing locally; there is a separate course for that.

Question Tool
Test an exact Kubernetes version, CI for operators kind
Lightweight cluster with ingress and load balancer out of the box k3d
Cluster and registry reproducible for a project ctlptl (+ kind or k3d)
Change code, see it in the cluster immediately Tilt or Skaffold
Production runs on Talos talosctl

Exercise: Context Traps

Answer without looking it up, then check against the outputs of this day:

  1. Which of the three commands switches the context: kind create cluster, k3d cluster create --kubeconfig-switch-context=false, ctlptl apply?
  2. What does kubectl config current-context show for the active cluster right after kind delete cluster?
  3. How do you protect yourself when you switch between the lab and a throwaway cluster in one shell?

Solution

  1. kind create cluster and ctlptl apply switch, k3d with the switch does not.
  2. error: current-context is not set: the context disappeared with the cluster.
  3. Every command with --context (or a variable like K=…), a separate shell with kubie ctx, and the prompt from Day 3 (kube-ps1), which always shows the context.

Save your progress? Sign up for free

Challenge

In a throwaway cluster, check whether the shop’s manifests from ~/werkzeuge/tag00/laden.yaml start in a fresh cluster without any history. Use kind; one node is enough. At the end, neither the cluster nor a context may be left over, and your context points to the lab again.

Solution

The cluster is called frisch (fresh):

kind create cluster --name frisch
kubectl --context kind-frisch apply -f ~/werkzeuge/tag00/laden.yaml
kubectl --context kind-frisch -n laden wait --for=condition=Available deploy --all --timeout=180s
kubectl --context kind-frisch -n lager get deploy,cronjob
kind delete cluster --name frisch
kubectl config use-context kind-werkzeuge
kind get clusters

Expected (excerpt):

…
deployment.apps/api condition met
deployment.apps/cache condition met
deployment.apps/web condition met
NAME                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/packer   1/1     1            1           …

NAME                     SCHEDULE       TIMEZONE   SUSPEND   ACTIVE   LAST SCHEDULE   AGE
cronjob.batch/inventur   */10 * * * *   <none>     False     0        <none>          …
Deleting cluster "frisch" ...
Deleted nodes: ["frisch-control-plane"]
Switched to context "kind-werkzeuge".
werkzeuge

A file that starts in a fresh cluster has no hidden dependencies on something that was once created by hand at some point. This is exactly how you check manifests in CI: spin up kind, apply, wait, throw away.

Save your progress? Sign up for free

Checkpoint

kind version; k3d version | head -1; ctlptl version
kind get clusters
k3d cluster list --no-headers | wc -l
kubectl config current-context

Expected:

kind v0.33.0 go1.26.7 linux/amd64
k3d version v5.9.0
v0.9.6, built 2026-09-10
werkzeuge
0
kind-werkzeuge

Interview Note

  • kind or k3d? kind for exact upstream versions and CI (that is what it is built for), k3d for a lightweight cluster with ingress and load balancer out of the box.
  • How do local images get into a local cluster? kind load/k3d image import for individual images, a local registry (ctlptl) for everyday work with many builds.
  • How do you test manifests or charts in the pipeline against a real API server? kind in the CI job, apply, wait, tests, kind export logs on errors, delete.

Enterprise Note

  • Throwaway clusters are only cheap if they really get thrown away. A kind delete at the end of every CI job (also on failure) and a nightly clean-up on shared build machines prevent full disks.
  • Local clusters pull images from the internet. In corporate networks, mirrors for the node images (kindest/node, rancher/k3s) and for Docker Hub belong in the configuration, otherwise builds fail on rate limits.
  • For development environments with many people, virtual clusters (vCluster) in a shared cluster are the alternative to many Docker clusters on laptops.

Contents

More