How to Install and Use Kind for Local Kubernetes Testing

Kind (Kubernetes IN Docker) is an excellent tool to create Kubernetes clusters locally using Docker containers. Here's a streamlined guide presented as a story for your infrastructure journey:


Step 1: Installing Kind

Imagine you’ve just arrived in a new world of local Kubernetes clusters, but first, you need the magic tool: kind. To install it, execute the following script on your host:

#!/bin/bash

# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo cp ./kind /usr/local/bin/kind
rm -rf kind

Once this script runs, kind becomes available system-wide:

[binita@test-kubernetes]# kind --version
kind version 0.20.0

Step 2: Bringing Up a Multi-Node Cluster

The goal? A 4-node Kubernetes cluster with 1 control plane and 3 workers. Start by creating a configuration file named config.yml:

# 4-node (3 workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.28.0
- role: worker
  image: kindest/node:v1.28.0
- role: worker
  image: kindest/node:v1.28.0
- role: worker
  image: kindest/node:v1.28.0

To start the cluster, execute:

[binita@test-kubernetes]# kind create cluster --config=config.yml

You’ll see something magical:

  • Nodes are prepared 📦.

  • Control plane spins up 🕹️.

  • Worker nodes join 🚜.

  • Networking and storage are configured 🔌 💾.

Once the cluster is ready, you can interact with it using:

kubectl cluster-info --context kind-kind

Step 3: Checking Cluster Status

You can verify your cluster setup with:

  1. Kind Command:

     kind get clusters
    
  2. kubectl Command:

     kubectl cluster-info
    
  3. Docker Command:
    Since Kind runs each Kubernetes node as a Docker container, you can inspect them:

     docker ps
    

    Output will show containers like kind-worker, kind-control-plane, etc., representing the nodes in your cluster.

  4. Node Details:

     kubectl get nodes
    

    Example output:

     NAME                 STATUS   ROLES           AGE   VERSION
     kind-control-plane   Ready    control-plane   22m   v1.28.0
     kind-worker          Ready    <none>          21m   v1.28.0
     kind-worker2         Ready    <none>          21m   v1.28.0
     kind-worker3         Ready    <none>          21m   v1.28.0
    

Step 4: Validating Client and Cluster Versions

Ensure your kubectl client matches the server version:

kubectl version

You’ll see output like this:

Client Version: v1.28.3
Server Version: v1.28.0

Takeaways

  • Kind runs each Kubernetes node as a Docker container within your host (physical machine or VM).

  • Kind is not for production; it’s designed for local testing and development.

  • Production-grade clusters spread nodes across multiple hosts, which is outside the scope of Kind.