kind: local Kubernetes cluster (minikube alternative)

kind Kubernetes kind local cluster

4 min read | by Jordi Prats

kind is a tool for runnint local Kubernetes clusters on Docker, just in the same way minikube can work (if configuring it to use docker). It was primarily designed for testing Kubernetes itself, but we can use it for local development or CI as well.

Taking a look at the releases page on GitHub, we'll find it available for both linux and Mac:

  • for Linux it supports amd64, arm64 and ppc64 (it might not be as relevant as it used to be)
  • for Mac it supports Intel (amd64) and M1/M2 (arm64)

To spin up a new local cluster the syntax it's just the same you would use with minikube:

$ kind create cluster
Creating cluster "kind" ...
 βœ“ Ensuring node image (kindest/node:v1.24.0) πŸ–Ό
 βœ“ Preparing nodes πŸ“¦
 βœ“ Writing configuration πŸ“œ
 βœ“ Starting control-plane πŸ•ΉοΈ
 βœ“ Installing CNI πŸ”Œ
 βœ“ Installing StorageClass πŸ’Ύ
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Not sure what to do next? πŸ˜…  Check out https://kind.sigs.k8s.io/docs/user/quick-start/

Creating a container just as minikube do:

$ kubectl get nodes
NAME                 STATUS   ROLES           AGE   VERSION
kind-control-plane   Ready    control-plane   68s   v1.24.0
$ docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED              STATUS              PORTS                                                                                                                                                                                                                           NAMES
34e50a57f958   kindest/node:v1.24.0     "/usr/local/bin/entr…"   About a minute ago   Up About a minute   127.0.0.1:63453->6443/tcp                                                                                                                                                                                                       kind-control-plane
bb55273c8df0   kicbase/stable:v0.0.33   "/usr/local/bin/entr…"   6 hours ago          Up 6 hours          0.0.0.0:49162->22/tcp, :::49162->22/tcp, 0.0.0.0:49161->2376/tcp, :::49161->2376/tcp, 0.0.0.0:49160->5000/tcp, :::49160->5000/tcp, 0.0.0.0:49159->8443/tcp, :::49159->8443/tcp, 0.0.0.0:49158->32443/tcp, :::49158->32443/tcp   minikube

We can delete it just as easy:

$ kind delete cluster
Deleting cluster "kind" ...

The big difference with minikube is that we can use a yaml manifest to configure the cluster, so for example, with the following manifest we can create a simulated two node cluster:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker

We just need to use the --config option to set it:

$ kind create cluster --config clusterdef.yaml
Creating cluster "kind" ...
 βœ“ Ensuring node image (kindest/node:v1.24.0) πŸ–Ό
 βœ“ Preparing nodes πŸ“¦ πŸ“¦
 βœ“ Writing configuration πŸ“œ
 βœ“ Starting control-plane πŸ•ΉοΈ
 βœ“ Installing CNI πŸ”Œ
 βœ“ Installing StorageClass πŸ’Ύ
 βœ“ Joining worker nodes 🚜
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Not sure what to do next? πŸ˜…  Check out https://kind.sigs.k8s.io/docs/user/quick-start/

Once it finishes doing its thing, we'll be able to see the new worker node:

$ kubectl get nodes
NAME                 STATUS     ROLES           AGE   VERSION
kind-control-plane   Ready      control-plane   32s   v1.24.0
kind-worker          NotReady   <none>          9s    v1.24.0

We can rename it as well using the yaml definition:

$ cat clusterdef.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: kindest
nodes:
- role: control-plane
- role: worker
$ kind create cluster --config clusterdef.yaml
Creating cluster "kindest" ...
 βœ“ Ensuring node image (kindest/node:v1.24.0) πŸ–Ό
 βœ“ Preparing nodes πŸ“¦ πŸ“¦
 βœ“ Writing configuration πŸ“œ
 βœ“ Starting control-plane πŸ•ΉοΈ
 βœ“ Installing CNI πŸ”Œ
 βœ“ Installing StorageClass πŸ’Ύ
 βœ“ Joining worker nodes 🚜
Set kubectl context to "kind-kindest"
You can now use your cluster with:

kubectl cluster-info --context kind-kindest

Have a nice day! πŸ‘‹

There are other options we can configure using this definition, we just need to check kind's documentation.

The only thing I find annoying is the fact that it uses .name instead of .metadata.name that you would expect on any kubernetes object (although it's not a kubernetes object)

$ kind create cluster --config clusterdef.yaml
ERROR: failed to create cluster: unable to decode config: yaml: unmarshal errors:
  line 3: field metadata not found in type v1alpha4.Cluster

Posted on 29/09/2021

Categories