Create Kubernetes Clusters with Kind

This tutorial will demonstrate how to deploy a Kubernetes Cluster locally on your laptop using the utility called kind.

Pre-Requisites

Kind uses docker to deploy "nodes" as containers, therefore docker is required before installing kind.

You will also require kubectl, which you can follow the link to install, if you don't have it installed already.

Installation

To install kind you can follow the installation guide at:

In short, if you are using MacOS, you can use homebrew:

brew install kind

If you are using Linux you can do the following:

curl -Lo kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
sudo install -o root -g root -m 0755 kind /usr/bin/kind
rm -f kind

Creating Clusters

This will demonstrate how to create clusters using the cli and how to create a cluster with a configuration file.

The versions for the nodes can be retrieved from their releases page.

CLI

To create a one-node cluster using the cli:

kind create cluster --name example --image kindest/node:v1.26.6

Then you can interact with the cluster using:

kubectl get nodes --context kind-example

Then delete the cluster using:

kind delete cluster --name kind-example

I highly recommend installing kubectx, which makes it easy to switch between kubernetes contexts.

Config File

The other method is using a yaml configuration file, in this case kind-config.yaml:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb
- role: worker
  image: kindest/node:v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb

In this example, we will create a cluster with 2 nodes, a control plane node and a worker. You can create the cluster using:

kind create cluster --name example --config kind-config.yaml

You can interact with the cluster using:

kubectl get nodes --context kind-example

You can then delete the cluster using:

kind delete cluster --name kind-example

If you want more configuration options, you can look at their documentation:

But one more example that I like using, is to define the port mappings:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
    listenAddress: "0.0.0.0"
  - containerPort: 443
    hostPort: 443
    protocol: TCP
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"

Thank You

Thanks for reading, if you enjoy my content please feel free to follow me on Twitter - @ruanbekker or visit me on my website - ruan.dev