Post

Start a Kubernetes cluster in seconds with Kind

Kind (Kubernetes in Docker) lets you spin up local Kubernetes clusters inside Docker containers in seconds.

Kind: Kubernetes In Docker (running Kubernetes inside a Docker container)

Kind is a tool that lets you create Kubernetes clusters inside Docker containers.

It was originally designed to test Kubernetes itself, but today it’s widely used to spin up local clusters for developing and testing applications, as well as in CI/CD pipelines. Kind is open source and completely free to use.

Prerequisites:

You’ll need a Docker or Docker-compatible environment to use Kind:

Personally, Orbstack remains my favorite tool for local development.

Installation

Depending on your operating system, follow the installation procedure.

Example:

1
2
3
4
# For ARM Macs
[ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-darwin-arm64
chmod +x ./kind
sudo mv kind /usr/local/bin/
1
2
3
4
# For Windows
curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.26.0/kind-windows-amd64
# Move the file to C:\your-folder\
# Add the folder path to your PATH

modifier-le-path-de-windows-ajouter-un-dossier-au-path

Verify the installation by running the following command:

1
kind

You should see output similar to this:

kind

! Kind is installed and ready to use 🎉.

Create a Kubernetes cluster with Kind:

It couldn’t be simpler — just run the following command:

1
kind create cluster

kind

Kind will create a Kubernetes cluster with a single node (a Linux machine, or in our case a Docker container), named kind by default.

To verify the cluster was created successfully, run:

1
kind get clusters

To create a cluster with a different name:

1
kind create cluster --name mon-cluster-x

Kind’s job is done — you can now use your cluster just like you would with a “real” Kubernetes cluster.

View your Kubernetes contexts:

1
kubectl config get-contexts

You should see output similar to this: kind

Now that you have a Kubernetes cluster ready, you can deploy an application with kubectl:

1
2
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --target-port=80 --type=ClusterIP

This will create an nginx deployment with a service exposed on port 80. To view the pods, services, and deployments:

1
kubectl get pods,svc,deploy

The service IP shown is not accessible from outside the cluster, so you’ll need to use port-forwarding to reach the application:

1
kubectl port-forward service/nginx 8080:80

kind

You can now access the application by navigating to: http://localhost:8080 kind

Delete a Kind cluster:

Once you’re done working with your cluster, you can delete it by running:

1
2
3
kind delete cluster
# or specify the cluster name if you gave it a different one:
kind delete cluster --name mon-cluster-x

Alternatives to Kind:

There are plenty of tools for creating local Kubernetes clusters — here are a few:

Similar to Kind:

  • minikube The very first tool for creating local Kubernetes clusters.
  • k3d Very similar to Kind, but uses k3s under the hood.
  • k0s

Desktop versions:

Conclusion

Kind is a very handy tool for creating local Kubernetes clusters to develop and test applications. I use it a lot to experiment with new concepts and tools in Kubernetes, without having to set up an entire infrastructure.

Tips and tricks

You can create a cluster with multiple nodes (containers):

1
kind create cluster --name mon-cluster-x --config=kind-config.yaml

Below is an example configuration file for an HA (High Availability) Kubernetes cluster with 3 control planes and 3 workers:

1
2
3
4
5
6
7
8
9
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: control-plane
  - role: control-plane
  - role: worker
  - role: worker
  - role: worker

References

This post is licensed under CC BY 4.0 by the author.