I’ve meaning to upgrade to an even easier to manage kubernetes cluster for testing and development than the one you can get from microk8s. Today I’m using kind (kubernetes in docker), this is specifically meant for testing and local development machines.
These days I’m on nixos so I went with a simple nix-shell -p kind -p kubectl to setup the tool.
Example config for 4 workers
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
- role: worker
❯ kind create cluster -n test --config 4-worker-cluster.yaml
Creating cluster "test" ...
✓ Ensuring node image (kindest/node:v1.34.0) 🖼
✓ Preparing nodes 📦 📦 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-test"
You can now use your cluster with:
kubectl cluster-info --context kind-test
Thanks for using kind! 😊
We verify what this has done to our config
❯ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
(my existing configuratino)
...
* kind-test kind-test kind-test
❯ kubectl cluster-info --context kind-test
Kubernetes control plane is running at https://127.0.0.1:39157
CoreDNS is running at https://127.0.0.1:39157/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6ec5f2806ac4 kindest/node:v1.34.0 "/usr/local/bin/entr…" About a minute ago Up About a minute 127.0.0.1:39157->6443/tcp test-control-plane
758a9749959b kindest/node:v1.34.0 "/usr/local/bin/entr…" About a minute ago Up About a minute test-worker
894b1de24498 kindest/node:v1.34.0 "/usr/local/bin/entr…" About a minute ago Up About a minute test-worker4
c143d5c8c64c kindest/node:v1.34.0 "/usr/local/bin/entr…" About a minute ago Up About a minute test-worker3
e726f48d9c21 kindest/node:v1.34.0 "/usr/local/bin/entr…" About a minute ago Up About a minute test-worker2
Images can be provided by a local registry but also can be “loaded” into the cluster, ideal for development and CI flows:
> kind load docker-image my-local-image:my-tag
# example to load a docker hub missage
> docker pull busybox:1.37.0-musl
> kind load docker-image busybox:1.37.0-musl --name test
Image: "busybox:1.37.0-musl" with ID "sha256:0188a8de47ca89b720586f01da7d7f870bdcf5f770b19f740291d716235d3107" not yet present on node "test-control-plane", loading...
Image: "busybox:1.37.0-musl" with ID "sha256:0188a8de47ca89b720586f01da7d7f870bdcf5f770b19f740291d716235d3107" not yet present on node "test-worker", loading...
Image: "busybox:1.37.0-musl" with ID "sha256:0188a8de47ca89b720586f01da7d7f870bdcf5f770b19f740291d716235d3107" not yet present on node "test-worker4", loading...
... (loads to all nodes)