DEV Community

Jensen Jose
Jensen Jose

Posted on

Setting Up Local Kubernetes Cluster with Kind

Hello everyone! Welcome back to the blog series on Mastering Kubernetes in this post, I’ll guide you through setting up Kubernetes on your local system using Kind.

Why Local Kubernetes Installation?

Before diving into managed Kubernetes services like EKS, AKS, or GKE, installing Kubernetes locally allows you to gain a deep understanding of its components and how they interact. Managed services abstract away many details, which limits your learning and troubleshooting capabilities.

Tools for Local Kubernetes Installation

There are several tools available for installing Kubernetes locally:

  • Minikube
  • K3s
  • K3d
  • Kind In this guide, we’ll use Kind (Kubernetes IN Docker), one of the most popular tools for local Kubernetes installations.

Image description

Prerequisites

Ensure you have the following installed on your system:

  • Go (1.17.5 or later)
  • Docker If you followed my previous posts, you should already have Docker installed. If not, please refer to those posts for installation instructions.

Installing Kind

Let’s start by installing Kind. Depending on your operating system, you can use a package manager:

For MacOS:

brew install kind
Enter fullscreen mode Exit fullscreen mode

For Windows:

choco install kind
Enter fullscreen mode Exit fullscreen mode

To create a Kubernetes cluster with Kind, use the following command:

kind create cluster --image <image-name> --name <cluster-name>
Enter fullscreen mode Exit fullscreen mode

For this tutorial, we'll use Kubernetes version 1.30:

kind create cluster --image kindest/node:v1.30.2 --name cka-cluster-one
Enter fullscreen mode Exit fullscreen mode

This command will pull the specified node image and create a cluster named cka-cluster-one.

Verifying the Cluster

To ensure your cluster is up and running, use the kubectl command-line tool. If you don't have kubectl installed, follow these steps:

// For MacOS
brew install kubectl

// For windows
choco install kubernetes-cli
Enter fullscreen mode Exit fullscreen mode

Image description

Creating a Multi-Node Cluster

For more advanced setups, you might want to create a cluster with multiple nodes. Here's how you can do it:

  1. Create a configuration file config.yaml with the following content:
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
Enter fullscreen mode Exit fullscreen mode
  1. Apply this configuration to create the cluster:
kind create cluster --config config.yaml --image kindest/node:v1.30.2 --name cka-cluster-two
Enter fullscreen mode Exit fullscreen mode
  1. Verify the nodes:
kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

You should see three nodes: one control-plane and two worker nodes.

Switching Contexts Between Clusters

When you have multiple clusters, you need to switch contexts to interact with the correct one. Use the following commands:

List all contexts:

kubectl config get-contexts
Enter fullscreen mode Exit fullscreen mode

Switch context:

kubectl config use-context kind-cka-cluster-one
Enter fullscreen mode Exit fullscreen mode

Conclusion

Setting up Kubernetes locally using Kind is a crucial step in understanding the core components and operations of Kubernetes. In the next post, we’ll dive into creating simple pods, understanding the difference between imperative and declarative commands, and learning the basics of YAML.

Happy learning!

For further reference, check out the detailed YouTube video here:

References:

  1. Kind Documentation - https://kind.sigs.k8s.io/
  2. Install Kubectl - https://kubernetes.io/docs/tasks/tools/
  3. Kubernetes Documentation - https://kubernetes.io/docs/home/

Top comments (0)