kind is primarily testing the kubernetes cluster locally with very minimal resources. Kind – Kubernetes in docker spins up the docker container as a node. If you are new to Kubernetes and looking for a k8s environment to practice, kind is the right tool. Minikube is another famous kubernetes available for developers and testing. Minikube can only spin up a single-node cluster but “Kind” supports all the deployment models.
Example:
- Single node cluster
- One master and multiple worker nodes,
- Multiple masters and multiple worker nodes. (HA control plane)
I will walk you through how to set up a “kind” cluster with multiple deployment models.
Pre-requisite:
- Windows or Mac Laptop/Desktop
- Docker Desktop
kind design:
As the name suggests, kubernetes will be running inside the docker in the kind cluster. Each node on kubernetes will be a docker container in the backend. kind is trying to leverage the k8s rather than reinventing the wheel. kubeadm bootstraps cluster with required node configuration, certificates, etc. kustomizeย will handle manifests with generated kubeadm configs.
Kind Installation:
Install a kind cluster using the package manager. If you are using MacBook, you can install using “brew install kind”. The kind project also offers pre-build binaries for Mac, Linux, and Windows operating systems.
On Mac using a brew package manager,
uxpro-$brew install kind
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 4 taps (ngrok/ngrok, fluxcd/tap, homebrew/core and homebrew/cask).
==> New Formulae
acl dagger freebayes jdtls localtunnel monika shadowsocks-rust ugit
age-plugin-yubikey ddcutil gemgen kmod ltex-ls nickel sophus vcluster
ansible-language-server ddh gi-docgen koka mapproxy nvchecker spirv-headers virt-manager
arxiv_latex_cleaner difftastic go@1.17 kubekey mariadb@10.6 observerward sqls vsce
autocannon easeprobe gops libapplewm mbt opendht sse2neon wasm-tools
bartib ecflow-ui highs libcython mbw openjdk@17 stanc3 wb32-dfu-updater_cli
bvm epinio httpyac libmarpa melody postgraphile stylish-haskell werf
cloudflare-quiche fclones hut libtpms micro_inetd powerman-dockerize testkube xkbcomp
compiledb flyctl ifacemaker libxcrypt minimap2 primecount tradcpp
cpi fortran-language-server imposm3 libxcvt mkfontscale quran trivy
criterion fourmolu inih libxfont2 mongodb-atlas-cli rslint tygo
==> Updated Formulae
Updated 2445 formulae.
==> Renamed Formulae
richmd -> rich-cli
==> Deleted Formulae
autopano-sift-c boost-python griffon gstreamermm komposition mozilla-addon-sdk szip
==> New Casks
abbyy-finereader-pdf dcp-o-matic-disk-writer jetbrains-gateway miln-movie-splitter osu rwts-pdfwriter windterm
accord dcp-o-matic-playlist-editor kdenlive miniwol paddle-easydl simplemind wpsoffice-cn
anypointstudio descript keysafe mixed-in-key-live paragon-camptune supernotes xiv-on-mac
audiorelay detail lapce mp3tag pingnoo todesk yattee
avifquicklook espanso macast mx-power-gadget polymc tomatobar
banana-cake-pop fmail2 manymc neovide postman-agent unicopedia-plus
bettermouse free-gpgmail mediahuman-audio-converter nitro-pdf-pro prowlarr vertcoin-core
cnkiexpress gdevelop medis nym-wallet readyapi vivid
dcp-o-matic-combiner irpf2022 mellel osp-tracker roonbridge warp
==> Updated Casks
Updated 1284 casks.
==> Deleted Casks
biopassfido finereader flip4mac lego-digital-designer mxsrvs profilemanager srware-iron thought-train zoom-outlook-plugin
bootchamp firestormos flvcd-bigrats multiscan-3b piskel sitebulb synergy vin047-abgx360
==> Downloading https://ghcr.io/v2/homebrew/core/kind/manifests/0.12.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/kind/blobs/sha256:544f1036a81b47d91b8ad81360fde3c063a4add7d50977f90992c9cada3eeaf8
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:544f1036a81b47d91b8ad81360fde3c063a4add7d50977f90992c9cada3eeaf8?se=2022-05-10T16%3A15%3A00Z&sig=TQ6TadVBwJ1FspQJ24Lpk6I1Vwwotl
######################################################################## 100.0%
==> Pouring kind--0.12.0.arm64_monterey.bottle.tar.gz
==> Caveats
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> Summary
๐บ /opt/homebrew/Cellar/kind/0.12.0: 8 files, 8.6MB
==> `brew cleanup` has not been run in the last 30 days, running now...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /Users/lingeswaran/Library/Caches/Homebrew/argocd--2.2.5... (40.7MB)
Removing: /Users/lingeswaran/Library/Caches/Homebrew/awscli--2.4.22... (17.3MB)
Removing: /Users/lingeswaran/Library/Caches/Homebrew/ca-certificates--2022-02-01... (120.8KB)
Removing: /Users/lingeswaran/Library/Caches/Homebrew/flux--0.27.3.tar.gz... (14.1MB)
Removing: /Users/lingeswaran/Library/Logs/Homebrew/helm... (64B)
Removing: /Users/lingeswaran/Library/Logs/Homebrew/python@3.9... (2 files, 2.5KB)
Pruned 0 symbolic links and 2 directories from /opt/homebrew
uxpro-$
uxpro-$kind create cluster
ERROR: failed to create cluster: failed to get docker info: command "docker info --format '{{json .}}'" failed with error: exec: "docker": executable file not found in $PATH
Command Output:
uxpro-$brew install docker
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> Updated Casks
Updated 3 casks.
Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker
==> Downloading https://ghcr.io/v2/homebrew/core/docker/manifests/20.10.15
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/docker/blobs/sha256:2cfb86b8bac67b5a9a4ca22de1f84d8cf1647c4e00ab068828593cf3cd23724b
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:2cfb86b8bac67b5a9a4ca22de1f84d8cf1647c4e00ab068828593cf3cd23724b?se=2022-05-10T16%3A20%3A00Z&sig=9%2BqbDvlC0k%2Bt8Q1iK2pe44hkLo
######################################################################## 100.0%
==> Pouring docker--20.10.15.arm64_monterey.bottle.tar.gz
==> Caveats
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> Summary
๐บ /opt/homebrew/Cellar/docker/20.10.15: 12 files, 55.2MB
==> Running `brew cleanup docker`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
uxpro-$
On Windows, run the following command from PowerShell to install kind package.
> choco install kind
Kind Binaries :
You can also directly download the kind binaries for the respective operating system.
Linux
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.15.0/kind-linux-amd64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind
Windows:
curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.15.0/kind-windows-amd64 Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe
Mac:
# for Intel Macs [ $(uname -m) = x86_64 ]&& curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.15.0/kind-darwin-amd64 # for M1 / ARM Macs [ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.15.0/kind-darwin-arm64 chmod +x ./kind mv ./kind /some-dir-in-your-PATH/kind
Creating k8s cluster using kind:
Kickstart Kind k8s cluster using the simple command “$ kind create cluster “. This command will bootstrap the cluster using the pre-built node image.
uxpro-$kind create cluster
Creating cluster "kind" ...
โ Ensuring node image (kindest/node:v1.23.4) ๐ผ
โ 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
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community ๐
uxpro-$
kind also supports named clusters. In other words, you can name the cluster by passing the flag “–name”.
uxpro-$kind create cluster --name uxpro
Creating cluster "uxpro" ...
โ Ensuring node image (kindest/node:v1.23.4) ๐ผ
โ Preparing nodes ๐ฆ
โ Writing configuration ๐
โ Starting control-plane ๐น๏ธ
โ Installing CNI ๐
โ Installing StorageClass ๐พ
Set kubectl context to "kind-uxpro"
You can now use your cluster with:
kubectl cluster-info --context kind-uxpro
Thanks for using kind! ๐
uxpro-$
uxpro-$kind get clusters
kind
uxpro
uxpro-$
How to access the k8s kind cluster?
By default, the kind command stores the cluster context in your home directory under .kube/config file.
uxpro-$kubectl cluster-info --context kind-kind
Kubernetes control plane is running at https://127.0.0.1:53978
CoreDNS is running at https://127.0.0.1:53978/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
uxpro-$kubectl cluster-info --context kind-uxpro
Kubernetes control plane is running at https://127.0.0.1:54161
CoreDNS is running at https://127.0.0.1:54161/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
uxpro-$
If you have multiple kind clusters and would like to set the default cluster context in Kube-config, then update “current-context” accordingly
uxpro-$pwd
/Users/lingeswaran/.kube
uxpro-$cat config |grep current-context
current-context: kind-uxpro
uxpro-$
Here are the running pods on cluster “uxpro”.
uxpro-$kubectl get nodes
NAME STATUS ROLES AGE VERSION
uxpro-control-plane Ready control-plane,master 21m v1.23.4
uxpro-$kubectl get pods
No resources found in default namespace.
uxpro-$kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-64897985d-b9ldc 1/1 Running 0 21m
kube-system coredns-64897985d-tb6sw 1/1 Running 0 21m
kube-system etcd-uxpro-control-plane 1/1 Running 0 21m
kube-system kindnet-hwsl8 1/1 Running 0 21m
kube-system kube-apiserver-uxpro-control-plane 1/1 Running 0 21m
kube-system kube-controller-manager-uxpro-control-plane 1/1 Running 0 21m
kube-system kube-proxy-7nm2x 1/1 Running 0 21m
kube-system kube-scheduler-uxpro-control-plane 1/1 Running 0 21m
local-path-storage local-path-provisioner-5ddd94ff66-8bhwz 1/1 Running 0 21m
uxpro-$
Advanced Kind cluster
By default, the kind creates the single node cluster. If you need a multi-node cluster, we can create a YAML manifest and create the cluster using it.
Example: If you are planning to create 3 master nodes and 3 worker nodes, create the YAML manifest like the below.
uxpro-$cat cluster.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
uxpro-$
Create a cluster using the following command.
uxpro-$kind create cluster --config cluster.yaml --name uxpro
Creating cluster "uxpro" ...
โ Ensuring node image (kindest/node:v1.23.4) ๐ผ
โ 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-uxpro"
You can now use your cluster with:
kubectl cluster-info --context kind-uxpro
Thanks for using kind! ๐
uxpro-$
List the running docker containers. You can see 3 workers containers, 3 master containers + load balance container will be running.
uxpro-$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f38fee836baa kindest/haproxy:v20220207-ca68f7d4 "haproxy -sf 7 -W -dโฆ" 9 minutes ago Up 9 minutes 127.0.0.1:54637->6443/tcp uxpro-external-load-balancer
f4ceb3d451c0 kindest/node:v1.23.4 "/usr/local/bin/entrโฆ" 9 minutes ago Up 9 minutes uxpro-worker3
af5acb420718 kindest/node:v1.23.4 "/usr/local/bin/entrโฆ" 9 minutes ago Up 9 minutes 127.0.0.1:54634->6443/tcp uxpro-control-plane
3672efac01d2 kindest/node:v1.23.4 "/usr/local/bin/entrโฆ" 9 minutes ago Up 9 minutes 127.0.0.1:54636->6443/tcp uxpro-control-plane2
52783af20bfb kindest/node:v1.23.4 "/usr/local/bin/entrโฆ" 9 minutes ago Up 9 minutes 127.0.0.1:54635->6443/tcp uxpro-control-plane3
136d00c5e9f3 kindest/node:v1.23.4 "/usr/local/bin/entrโฆ" 9 minutes ago Up 9 minutes uxpro-worker2
e89fbfafd489 kindest/node:v1.23.4 "/usr/local/bin/entrโฆ" 9 minutes ago Up 9 minutes uxpro-worker
uxpro-$
How do spin up the first pod on the kind cluster?
1. Create a new pod manifest and store it in web1.yaml.
uxpro-$kubectl run web1 --image=nginx --dry-run=client -o yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: web1
name: web1
spec:
containers:
- image: nginx
name: web1
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
uxpro-$kubectl run web1 --image=nginx --dry-run=client -o yaml > web1.yaml
2. Create a pod using the created manifest.
uxpro-$kubectl create -f web1.yaml
pod/web1 created
uxpro-$kubectl get pod
NAME READY STATUS RESTARTS AGE
web1 0/1 ContainerCreating 0 6s
uxpro-$kubectl get pod
NAME READY STATUS RESTARTS AGE
web1 1/1 Running 0 66s
uxpro-$kubectl describe po web1
Name: web1
Namespace: default
Priority: 0
Service Account: default
Node: uxpro-worker2/172.18.0.5
Start Time: Sat, 10 Sep 2022 19:53:59 +0530
Labels: run=web1
Annotations: <none>
Status: Running
IP: 10.244.3.2
IPs:
IP: 10.244.3.2
Containers:
web1:
Container ID: containerd://62e8957861e3154bc8cb485d2ef2031411c17a8f202212c36ec3bd5a87531bfd
Delete Kind cluster:
Cleaning up the kind cluster is easy. The following command will delete the default “kind” cluster.
uxpro-$kind delete cluster Deleting cluster "kind" ... uxpro-$
To delete the named cluster, use the following command.
uxpro-$kind delete cluster --name uxpro Deleting cluster "uxpro" ... uxpro-$
To delete all the kind clusters on your host, use the following command.
uxpro-$kind delete clusters --all Deleted clusters: ["uxpro"] uxpro-$
How do spin up specific versions of the kubernetes cluster using kind ?
kind supports multiple versions of the kubernetes cluster. You need to explicitly define in the kind cluster manifest like below with the image version.
uxpro-$cat cluster_1.19.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane image: kindest/node:v1.19.16@sha256:707469aac7e6805e52c3bde2a8a8050ce2b15decff60db6c5077ba9975d28b98 - role: worker image: kindest/node:v1.19.16@sha256:707469aac7e6805e52c3bde2a8a8050ce2b15decff60db6c5077ba9975d28b98 uxpro-$
How to identify the checksum and node image version ? Checkout the kind release page.
Let’s spin up a cluster using the specific version kubernetes cluster.
uxpro-$kind create cluster --name k8s119 --config cluster_1.19.yaml
Creating cluster "k8s119" ...
โ Ensuring node image (kindest/node:v1.19.16) ๐ผ
โ Preparing nodes ๐ฆ ๐ฆ
โ Writing configuration ๐
โ Starting control-plane ๐น๏ธ
โ Installing CNI ๐
โ Installing StorageClass ๐พ
โ Joining worker nodes ๐
Set kubectl context to "kind-k8s119"
You can now use your cluster with:
kubectl cluster-info --context kind-k8s119
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community ๐
uxpro-$kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s119-control-plane Ready master 41s v1.19.16
k8s119-worker NotReady <none> 7s v1.19.16
uxpro-$
Hope this article gives quick glimpse about kind tool. It’s one of the quickest method to spin up k8s cluster for testing. If you are beginner to k8s or developer who would like to test the deployment, kind is the right tool.
Leave a Reply