Creating multi-node Kubernetes test clusters with KIND (Kubernetes In Docker)


The Kubernetes ecosystem is rapidly evolving, which means tools, frameworks and ways to approach running Kubernetes in production are constantly changing. To keep up with these changes I used to use a custom script to provision test clusters with kubeadm. This worked well, but it took an excessive amount of time to spin up clusters to test features. When you are excited about testing a new tool or feature you want to do it NOW. You don’t want to wait ten minutes for the provisioning process to complete.

Well, lucky for me Kris Nova did a TGIK on KIND (Kubernetes In Docker). I was blown away by how quickly you can provision a test cluster on a modern laptop and have used it ever since. On my meager little MacBook Air I can provision a test cluster in 20-seconds, and can delete it in under 5-seconds. This is absolutely mind blowing!

This past weekend I was trying to develop a deep understanding of taints, tolerations and node affinities. To really dive deep into these features you need to have more than one worker available. By default, KIND will provision a cluster with a single worker node. This works great for the vast majority of test cases but comes up short when you are trying to test features that require multiple worker or control plane nodes. Luckily KIND is extremely extensible, and allows advanced topogies to be described in a YAML file similar to the following:

$ cat kind.yml

kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
- role: worker
- role: worker

In the example above I am creating one control plane node and two workers. If you need more control or worker nodes you can add additional lines to the YAML file. To tell KIND to use this configuration you can use the “–config” option:

$ kind create cluster --name=foo --config=./kind.yml

Once KIND creates the cluster you can export the KUBECONFIG variable and begin testing:

$ export KUBECONFIG="$(kind get kubeconfig-path --name="foo")"

$ kubectl get nodes

NAME                STATUS     ROLES    AGE   VERSION
foo-control-plane   NotReady   master   43s   v1.15.0
foo-worker          NotReady   <none>   6s    v1.15.0
foo-worker2         NotReady   <none>   6s    v1.15.0

This is amazing and KIND is one of the coolest tools to hit the K8S community. Digging it!

This article was posted by on 2019-10-07 00:00:00 +0000 UTC