[Kubernetes (K8S) Kind] Use Homebrew (brew) to install Kind Kubernetes (K8S) cluster on macOS

Kind

kind is a tool for running local Kubernetes clusters using Docker container “nodes”.
kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

Prerequisites

  • Homebrew

    Homebrew is the Missing Package Manager for macOS (or Linux).

    For more information about installing and using Homebrew, see the Homebrew - https://brew.sh/.

    Install Homebrew (brew).

    1
    % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Installation

1
% brew install kind

For more detailed instructions see the user guide - https://kind.sigs.k8s.io/docs/user/quick-start.

Create cluster

Run kind create cluster -h to get command help:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
% kind create cluster -h
Creates a local Kubernetes cluster using Docker container 'nodes'

Usage:
kind create cluster [flags]

Flags:
--config string path to a kind config file
-h, --help help for cluster
--image string node docker image to use for booting the cluster
--kubeconfig string sets kubeconfig path instead of $KUBECONFIG or $HOME/.kube/config
--name string cluster name, overrides KIND_CLUSTER_NAME, config (default kind)
--retain retain nodes for debugging when cluster creation fails
--wait duration wait for control plane node to be ready (default 0s)

Global Flags:
--loglevel string DEPRECATED: see -v instead
-q, --quiet silence all stderr output
-v, --verbosity int32 info log verbosity

Single node cluster

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
% kind create cluster
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.21.1) 🖼
✓ Preparing nodes 📦 📦 📦 📦 📦 📦
✓ Configuring the external load balancer ⚖️
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining more control-plane nodes 🎮
✓ 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/

Multiple nodes cluster

First, create a config file kind-multiple-control-plane.yaml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# cat kind-multiple-control-plane.yaml

# a cluster with 3 control-plane nodes and 3 workers
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker

networking:
# WARNING: It is _strongly_ recommended that you keep this the default
# (127.0.0.1) for security reasons. However it is possible to change this.
apiServerAddress: "192.168.80.33"
# By default the API server listens on a random open port.
# You may choose a specific port but probably don't need to in most cases.
# Using a random port makes it easier to spin up multiple clusters.
apiServerPort: 58014

Then, run kind create command to create a cluster.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
% kind create cluster --config kind-multiple-control-plane.yaml
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.21.1) 🖼
✓ Preparing nodes 📦 📦 📦 📦 📦 📦
✓ Configuring the external load balancer ⚖️
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining more control-plane nodes 🎮
✓ 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/

Check cluster info.

1
2
3
4
5
% kubectl cluster-info --context kind-kind
Kubernetes control plane is running at https://192.168.80.33:58014
CoreDNS is running at https://192.168.80.33:58014/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Run kubect get nodes to check cluster nodes.

1
2
3
4
5
6
7
8
% kubectl get nodes --context kind-kind
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane,master 5m39s v1.21.1
kind-control-plane2 Ready control-plane,master 5m10s v1.21.1
kind-control-plane3 Ready control-plane,master 4m16s v1.21.1
kind-worker Ready <none> 3m58s v1.21.1
kind-worker2 Ready <none> 3m58s v1.21.1
kind-worker3 Ready <none> 3m58s v1.21.1

Run docker ps to cheker docker containers.

% docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS         PORTS                         NAMES
714bb9aea94c   kindest/haproxy:v20200708-548e36db   "/docker-entrypoint.…"   6 minutes ago   Up 6 minutes   192.168.80.33:58014->6443/tcp   kind-external-load-balancer
741bd68261fa   kindest/node:v1.21.1                 "/usr/local/bin/entr…"   7 minutes ago   Up 6 minutes   127.0.0.1:50252->6443/tcp     kind-control-plane
39d98d72e35a   kindest/node:v1.21.1                 "/usr/local/bin/entr…"   7 minutes ago   Up 6 minutes                                 kind-worker2
da46761e4c49   kindest/node:v1.21.1                 "/usr/local/bin/entr…"   7 minutes ago   Up 6 minutes   127.0.0.1:50253->6443/tcp     kind-control-plane2
88f00272efe0   kindest/node:v1.21.1                 "/usr/local/bin/entr…"   7 minutes ago   Up 6 minutes                                 kind-worker
f054dd65b71e   kindest/node:v1.21.1                 "/usr/local/bin/entr…"   7 minutes ago   Up 6 minutes                                 kind-worker3
8ad315d2d8e9   kindest/node:v1.21.1                 "/usr/local/bin/entr…"   7 minutes ago   Up 6 minutes   127.0.0.1:50254->6443/tcp     kind-control-plane3

## References

[1] [kind - https://kind.sigs.k8s.io/](https://kind.sigs.k8s.io/)

[2] [Homebrew - https://brew.sh/](https://brew.sh/)

[3] [Install Tools | Kubernetes - https://kubernetes.io/docs/tasks/tools/](https://kubernetes.io/docs/tasks/tools/)

[4] [Kubernetes](https://kubernetes.io/)