In this blog, I will guide you through the process of setting up a multi-node Kubernetes cluster using Kind. Kind is a tool that allows you to run local Kubernetes clusters using Docker container nodes. This is a great way to learn and experiment with Kubernetes without having to set up a cloud-based cluster.
What is a Cluster?
A Kubernetes (K8s) cluster is a set of interconnected machines (nodes) that work together to deploy, manage, and scale containerized applications.
Installation
To locally install k8s, we’re using kind package manager.
Kind is a tool for running local Kubernetes clusters using Docker containers. It is primarily designed for development and testing purposes, allowing you to create and manage Kubernetes clusters on your local machine or in CI/CD pipelines.
To install kind, we use the following command on Linux:
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
Creating a Cluster
Once Kind is installed, you can create a cluster using the following command:
kind create cluster --name my-cluster
Accessing the Cluster
To access the cluster, you will need to use the kubectl
command-line tool. You can configure kubectl
to use the Kind cluster by running the following command:
Install Kubectl
sudo snap install kubectl --classic
kubectl version --client
kubectl config use-context kind-my-cluster
Verifying the Cluster
To verify that the cluster is running, you can run the following command:
kubectl get nodes
kubectl get cluster-info
To check the current context
kubectl config current-context
Creating a Multi-Node Cluster
Create a config.yaml
file defining the cluster structure
Config file contents:
# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
Command for creating the cluster using the config file:
kind create cluster --image kindest/node:v1.29.4@sha256:3abb816a5b1061fb15c6e9e60856ec40d56b7b52bcea5f5f1350bc6e2320b6f8 --name kind-cluster-2 --config config.yaml
To list all the context
kubectl config get-contexts
You will find two contexts are there, means we have created two cluster kind-my-cluster
and kind-cluster-2
. Now we can choose kubectl
should collect data from which cluster.
To get into a cluster:
kubectl config use-context kind-cluster-2
To verify the cluster was set up correctly, I ran:
kubectl get nodes
This listed all the control plane and worker nodes running inside Docker containers. To cross-check, I also ran:
docker ps
This confirmed that the nodes were indeed Docker containers, a key feature of KIND. Key Learnings and Benefits of Using KIND
KIND is perfect for setting up a lightweight local Kubernetes environment without needing a full VM or cloud setup. Single-node and multi-node configurations can be easily spun up with specific Kubernetes versions, making it ideal for testing. Docker containers as nodes: KIND uses Docker containers to simulate Kubernetes nodes, keeping everything compact and easy to manage.
Final Thoughts
Setting up KIND for Kubernetes is a straightforward process and a great way to practice Kubernetes in a local, resource-efficient environment. It’s an excellent tool for learning, testing, and rapid iteration before scaling to larger environments.
To delete the cluster
kind delete cluster --name <mention its name>