Setting Up Local Kubernetes Cluster with Kind
Tags: kind, kubernets, containers
Published: 2024-06-25 17:54:15

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rexqciv5dw4zqsmiwzgk.jpeg)

### 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
```

#### For Windows:
```
choco install kind
```

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

```
kind create cluster --image <image-name> --name <cluster-name>
```
For this tutorial, we'll use Kubernetes version 1.30:
```
kind create cluster --image kindest/node:v1.30.2 --name cka-cluster-one
```
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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnb99szbch3oz9f5o8ga.png)


## 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
```
2. Apply this configuration to create the cluster:
```
kind create cluster --config config.yaml --image kindest/node:v1.30.2 --name cka-cluster-two
```
3. Verify the nodes:
```
kubectl get nodes
```
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
```
Switch context:
```
kubectl config use-context kind-cka-cluster-one
```
### 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:
{% embed https://www.youtube.com/watch?v=RORhczcOrWs&list=WL&index=14 %}

### 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/