Back to Blog
Originally published on Medium.Read Original Article
2022-03-19

Get Started with Kubernetes using kind

Get Started with Kubernetes using kind kind (Kubernetes in Docker) is a tool for running local Kubernetes clusters using Docker container “n...

Share Editorial
Get Started with Kubernetes using kind

Get Started with Kubernetes using kind

kind* (Kubernetes in Docker) 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.*

**Kind **uses Docker container to run Kubernetes nodes. It supports creating multiple clusters as opposed to single cluster in Minikube. It also supports multi-node setup which could be very helpful for DevOps trial. It also supports creating a HA based kubernetes ecosystem locally.

Prerequisites

To install kind, you need to have Docker installed and should be up and running.

Installation

  • To download and install kind in debian/ubuntu or WSL2 please follow the below steps. Change the version to the desired one.
text
version=v0.12.0
text
curl -L "https://kind.sigs.k8s.io/dl/${version}/kind-$(uname)-amd64" -o /usr/local/bin/kind
chmod +x /usr/local/bin/kind
  • You can verify the installation using the below command:
text
kind version
kind v0.12.0 go1.17.8 linux/amd64

Create Kubernetes Cluster with Single Node

  • You can create cluster using the command kind create cluster In the process, kind will pull the node docker image which contains necessary components like kubelet, kubeadm, docker, systemd and core images such as etcd, coredns, pause, kube-apiserver etc.
text
export CLUSTER_NAME=cluster-1
text
~ kind create cluster --name CLUSTER_NAME
Creating cluster "cluster-1" ...
 ✓ Ensuring node image (kindest/node:v1.23.4) 🖼
 ✓ Preparing nodes 📦
 ✓ Writing configuration 📜
 ✓ Starting control-plane 🕹️
 ✓ Installing CNI 🔌
 ✓ Installing StorageClass 💾
Set kubectl context to "kind-cluster-1"
You can now use your cluster with:
text
kubectl cluster-info --context kind-cluster-1
text
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂

You can create multiple clusters using the above command. If you then want to connect to particular cluster, use the below command

text
kubectl config use-context kind-$CLUSTER_NAME

You can get the nodes using the kubectl get nodes command. This will return you a single node.

text
kubectl get nodes
NAME                      STATUS     ROLES                  AGE   VERSION
cluster-1-control-plane   NotReady   control-plane,master   18s   v1.23.4

Get all the clusters created in kind

text
kind get clusters        
cluster-1

Delete Cluster: kind delete cluster --name $CLUSTER_NAME

text
kind delete cluster --name cluster-1
Deleting cluster "cluster-1" ...

Create Kubernetes Cluster with multi node

text
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
  • The above configuration file will create one control-plane and two worker nodes.
  • To create a cluster using the above configuration, please pass — config to the configuration.
text
kind create cluster --name $CLUSTER_NAME --config multi-node.yaml
Creating cluster "my-kind-cluster" ...
✓ Ensuring node image (kindest/node:v1.23.4) 🖼
✓ Preparing nodes 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-cluster-1"
You can now use your cluster with:
text
kubectl cluster-info --context kind-cluster-1
text
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂
  • As you can see your three node cluster is up and running
text
kubectl get nodes
NAME                            STATUS   ROLES                  AGE   VERSION
cluster-1-control-plane   Ready    control-plane,master   60s   v1.23.4
cluster-1-worker          Ready                      32s   v1.23.4
cluster-1-worker2         Ready                      32s   v1.23.4

Similarly, if you want multiple control planes, you just need to add subsequent roles in the yaml file as you did for the worker node.

Wrapping Up

Kind is super powerful and could be very helpful if you are a DevOps guy. This could be helpful for developers too if you do not intend to use Docker Desktop or Minikube. If you don’t want to spend hours building Kubernetes cluster in the cloud, kind is a tool for you.

Clap, share, comment, give me feedback. I’d love to hear your thoughts! Happy Learning.

Sponsored Advertisement