Setting Up a Local Kubernetes Development Environment with kubectl and Kind

shrinivas joshishrinivas joshi
4 min read

In the world of container orchestration, Kubernetes has established itself as the industry standard. However, getting started with Kubernetes can be intimidating, especially when it comes to setting up a local development environment. This tutorial will walk you through installing two essential tools for local Kubernetes development: kubectl (the Kubernetes command-line tool) and kind (Kubernetes IN Docker).

Why Local Kubernetes Development?

Before diving into the installation process, let’s understand why you might want a local Kubernetes environment:

  1. Learning: Practice Kubernetes concepts without worrying about cloud costs

  2. Development: Test applications in an environment similar to production

  3. CI/CD: Verify Kubernetes deployments before pushing to staging or production

  4. Experimentation: Try new configurations or features in a safe environment

Prerequisites

This guide assumes you’re using a Linux-based system. The script will work on most Debian/Ubuntu and Red Hat-based distributions.

The Installation Script

Here’s a simple bash script that will install both kubectl and kind on your Linux machine:

#!/bin/bash

# Determine the architecture
ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]]; then
  ARCH="amd64"
elif [[ "$ARCH" == "i386" ]]; then
  ARCH="386"
else
  echo "Unsupported architecture: $ARCH"
  exit 1
fi

# Install kubectl

# Download kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl"

# Make kubectl executable
chmod +x ./kubectl

# Move kubectl to your PATH
sudo mv ./kubectl /usr/local/bin/kubectl

# Test the installation
kubectl version --client

echo "kubectl has been installed successfully."

# Install kind

# Download kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-${ARCH}

# Make kind executable
chmod +x ./kind

# Move kind to your PATH
sudo mv ./kind /usr/local/bin/kind

# Test the installation
kind version

echo "kind has been installed successfully."

Understanding the Script

Let’s break down what this script does:

1. Architecture Detection

ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]]; then
  ARCH="amd64"
elif [[ "$ARCH" == "i386" ]]; then
  ARCH="386"
else
  echo "Unsupported architecture: $ARCH"
  exit 1
fi

This part detects your system’s architecture and maps it to the format expected by the kubectl and kind downloads. It supports x86_64 (64-bit) and i386 (32-bit) architectures.

2. Installing kubectl

# Download kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl"
# Make kubectl executable
chmod +x ./kubectl
# Move kubectl to your PATH
sudo mv ./kubectl /usr/local/bin/kubectl
# Test the installation
kubectl version --client

This section:

  • Downloads the latest stable version of kubectl for your architecture

  • Makes the downloaded file executable

  • Moves it to /usr/local/bin so it's available in your PATH

  • Verifies the installation by checking the version

3. Installing kind

# Download kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-${ARCH}
# Make kind executable
chmod +x ./kind
# Move kind to your PATH
sudo mv ./kind /usr/local/bin/kind
# Test the installation
kind version

Similarly, this part:

  • Downloads kind version 0.11.1 for your architecture

  • Makes it executable

  • Moves it to your PATH

  • Verifies the installation

Using Your New Tools

Now that you have both tools installed, here’s how to get started:

Create Your First Cluster

kind create cluster --name my-first-cluster

This command creates a new Kubernetes cluster named “my-first-cluster” running inside Docker containers on your local machine.

Interact with Your Cluster

kubectl get nodes

This will show you the nodes in your newly created cluster. Since kind creates a single-node cluster by default, you should see just one node listed.

Deploy a Sample Application

kubectl create deployment hello-node --image=k8s.gcr.io/serve_hostname
kubectl expose deployment hello-node --type=NodePort --port=8080

These commands deploy a simple application and expose it as a service.

Going Further

Once you’re comfortable with the basics, you can:

  1. Create multi-node clusters:
kind create cluster --config=multi-node.yaml

Where multi-node.yaml specifies multiple nodes.

2. Mount local code into your cluster:

kind create cluster --config=local-mount.yaml

Where local-mount.yaml includes volume mounts.

3. Test different Kubernetes versions:

kind create cluster --image kindest/node:v1.20.7

4. Install Kubernetes Dashboard:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml

Conclusion

Setting up a local Kubernetes environment doesn’t have to be complicated. With kubectl and kind, you can have a functional Kubernetes cluster running on your local machine in minutes. This allows you to learn, develop, and experiment with Kubernetes without needing to provision cloud resources.

The approach outlined in this tutorial is particularly useful for developers who want to understand Kubernetes concepts or test their applications in a Kubernetes environment before deploying to production.

What Kubernetes projects are you working on? Have you found other useful tools for local development? Share your experiences in the comments!


Note: The script and instructions in this post are current as of March 2025. Be sure to check the official documentation for kubectl and kind for any updates or changes.

0
Subscribe to my newsletter

Read articles from shrinivas joshi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

shrinivas joshi
shrinivas joshi