Open In App

How To Use Kind To Deploy Kubernetes Clusters?

Kind also referred to as Kubernetes in Docker is a popular open-source tool used for running a Kubernetes cluster locally. Kind uses Docker containers as Cluster Nodes making it substantially faster than its alternatives like Minikube or Docker Desktop which uses a Virtual Machine. Kind is commonly used to test Kubernetes clusters on local machines. Kind is useful specifically when the user wants to create a multi-Node cluster since Minikube or Docker Desktop does not provide any such functionality. In this article we will learn about KinD and see how to use KinD for Deploying Kubernetes clusters.

What Does Kind Do?

Kind also referred to as Kubernetes in Docker is a popular open-source tool used for running a Kubernetes cluster locally. Kind uses Docker containers as Cluster Nodes making it substantially faster than its alternatives like Minikube or Docker Desktop which uses a Virtual Machine. Kind is commonly used to test Kubernetes clusters on local machines. Kind is useful specifically when the user wants to create a multi-Node cluster since Minikube or Docker Desktop does not provide any such functionality. It can also be useful when the user wants to test his or her application when one Node goes down or when the application is shut down on one Node and restarts on another. Kind consists of the following packages and tools:



For Linux users, Kind comes as a better option than Minikube also because of the reason that it does not create a Virtual Machine when used in Linux hence it is much more faster than Minikube. This is not the case for Windows and MacOS since they cannot run containers.

Features Of Kind

Kind has five important features as a tool for running Kubernetes locally:



Deploying An Application On Kind Kubernetes Cluster: A Step-By-Step Guide

Step 1: Installation Of Kind

# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

kind

And you will see the following result as confirmation:

Step 2: Creating A Kind Cluster

kind create cluster
kind create cluster --name [NAME_OF_THE_CLUSTER]
kind create cluster --name gfg-cluster

Step 3: Checking The Number Of Nodes In The Cluster

docker container ls

kubectl get nodes

And we can see a single Node running by the name “gfg-cluster-control-plane”.

Step 4: Creating Multiple Clusters Using Kind

kind create cluster --name gfg-cluster-two

 kind delete cluster --name gfg-cluster-two

Step 5: Creating Cluster Using Config Files

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker
touch multi-node-cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: kind
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 8080
protocol: TCP
- containerPort: 443
hostPort: 44300
protocol: TCP
- role: worker
kind create cluster --config=multi-node-cluster.yaml --name=multi-node-cluster

kubectl get nodes

Step 6: Creating The Configuration File

Now that we have a Cluster up and running, let’s deploy an application on that cluster. Here is a configuration file that will deploy a simple HTTP echo server on our Cluster, it has three sections:

kind: Pod
apiVersion: v1
metadata:
name: test-app
labels:
app: test-app
spec:
containers:
- name: test-app
image: hashicorp/http-echo:latest
args:
- "-text=The test has been successful!"
---
kind: Service
apiVersion: v1
metadata:
name: test-service
spec:
selector:
app: test-app
ports:
- port: 5678
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
spec:
rules:
- http:
paths:
- pathType: Prefix
path: "/app"
backend:
service:
name: test-service
port:
number: 5678
touch test-app.yaml

Step 7. Deploying The Application

kubectl apply -f test-app.yaml
 kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

kubectl port-forward service/test-service 5678:5678

Step 7: Testing The application

curl localhost:5678

Some Common Kind Commands

1. Creating A Cluster

kind create cluster
kind create cluster --name=[NAME_OF_CLUSTER]
kind create cluster --image=[IMAGE]
kind create cluster --config=[FILE_NAME]
kind create cluster --wait [TIME]

2. Loading An Image Into Your Cluster

kind load docker-image [DOCKER_IMAGE_NAME]
kind load image-archive /my-image-archive.tar

3. Get The List Of Clusters

 kind get clusters

4. Exporting Logs

kind export logs

5. Deleting The Kind Cluster

kind delete cluster
kind delete cluster --name [NAME_OF_CLUSTER]

Conclusion

In this article we learned about KinD and how to use it to deploy Kubernetes clusters. KinD also referred as Kubernetes in Docker is a popular open-source tool used for running a Kubernetes clusters locally. Kind uses Docker containers as Cluster Nodes making it substantially faster than it’s alternatives like Minikube or Docker Desktop which uses a Virtual Machine. Kind is commonly used to test Kubernetes clusters on local machines. We hope that this article taught you about what Kind is, how it works and how to deploy an application using Kind. Make sure to follow other articles on GeeksforGeeks to know about more tools in DevOps.

Kubernetes Kind – FAQ’s

What Are The Prerequisites Before Learning Kind?

Before studying about Kind. You should have fundamental knowledge of Docker and Kubernetes.

What Are The Ways To Create A Cluster Using Kind?

There are two ways you can create a Kubernetes cluster using Kind:

1. Using the following terminal command

kind create cluster –name [NAME_OF_THE_CLUSTER]

2. Using a configuration file

What Is Kind Used For?

Kind is used to create Kubernetes Clusters on your local machines.

Is Kind Better Than Minikube?

The answer to this depends which use case you want these tools for. What Kind offers better than its alternatives like Minikube or Docker Desktop is the ability to create multiple clusters. Other than this Kind also allows the users to create clusters using config files.

Is Kind Open-source Tool?

Yes, Kind is an open-source tool under Kubernetes project.


Article Tags :