Skip to content

Setting Up Kubernetes Clusters with KIND

Published: at 12:00 PM

Setting Up Kubernetes Clusters with KIND

In this post, we’ll walk through the process of setting up Kubernetes clusters using KIND (Kubernetes IN Docker) on a local machine. We’ll cover both single-node and multi-node cluster setups, as well as some basic Kubernetes operations.

Prerequisites

Before we begin, make sure you have the following installed on your machine:

Single-Node Cluster Setup

Let’s start by creating a single-node KIND cluster with Kubernetes version 1.29.

kind create cluster --name single-node-cluster --image kindest/node:v1.29.0

This command creates a single-node Kubernetes cluster named “single-node-cluster” using Kubernetes version 1.29.

After creating the cluster, we can delete it using:

kind delete cluster --name single-node-cluster

Multi-Node Cluster Setup

Now, let’s create a multi-node cluster with specific requirements:

First, we need to create a configuration file for our multi-node cluster. Let’s call it multi-node-config.yaml:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: cka-cluster2
nodes:
  - role: control-plane
  - role: worker
  - role: worker
  - role: worker

Now, we can create our multi-node cluster:

kind create cluster --config multi-node-config.yaml --image kindest/node:v1.30.0

Note: As of my knowledge cutoff in April 2024, Kubernetes 1.30 might not be available. If that’s the case, use the latest available version.

Installing kubectl

To interact with our Kubernetes cluster, we need to install kubectl. Here’s how to do it on a Linux system:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

For other operating systems, please refer to the official Kubernetes documentation.

Setting the Current Context

After creating our multi-node cluster, we need to set the current context to use it:

kubectl config use-context kind-cka-cluster2

Verifying the Cluster

Let’s verify that our cluster is set up correctly:

kubectl get nodes

You should see output similar to this:

NAME                        STATUS   ROLES           AGE     VERSION
cka-cluster2-control-plane   Ready    control-plane   5m      v1.30.0
cka-cluster2-worker          Ready    <none>          4m30s   v1.30.0
cka-cluster2-worker2         Ready    <none>          4m30s   v1.30.0
cka-cluster2-worker3         Ready    <none>          4m30s   v1.30.0

Verifying Nodes as Docker Containers

Remember, in KIND, each “node” is actually a Docker container. We can verify this by running:

docker ps

You should see four containers running, corresponding to our Kubernetes nodes.

Docker Control Plane Docker Container Worker Node 1 Docker Container Worker Node 2 Docker Container Worker Node 3 Docker Container KIND (Kubernetes IN Docker)

Conclusion

We’ve successfully set up both single-node and multi-node Kubernetes clusters using KIND. This approach allows us to create and manage Kubernetes clusters locally, which is incredibly useful for development and testing purposes.

Remember, each “node” in our KIND cluster is actually a Docker container, providing a lightweight and flexible way to work with Kubernetes on your local machine.

References

  1. KIND (Kubernetes IN Docker) Documentation
  2. Kubernetes Official Documentation: Installing kubectl
  3. KIND: Quick Start Guide
  4. KIND: Configuration