Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
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:
- Docker
- kubectl (we’ll install this during the process)
- KIND
Single-Node Cluster Setup#
Let’s start by creating a single-node KIND cluster with Kubernetes version 1.29.
1kind create cluster --name single-node-cluster --image kindest/node:v1.29.0This 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:
1kind delete cluster --name single-node-clusterMulti-Node Cluster Setup#
Now, let’s create a multi-node cluster with specific requirements:
- Cluster Name: cka-cluster2
- Nodes: 1 Control plane and 3 worker nodes
- Kubernetes Version: 1.30
First, we need to create a configuration file for our multi-node cluster. Let’s call it multi-node-config.yaml:
1kind: Cluster2apiVersion: kind.x-k8s.io/v1alpha43name: cka-cluster24nodes:5 - role: control-plane6 - role: worker7 - role: worker8 - role: workerNow, we can create our multi-node cluster:
1kind create cluster --config multi-node-config.yaml --image kindest/node:v1.30.0Note: 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:
1curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"2chmod +x kubectl3sudo 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:
1kubectl config use-context kind-cka-cluster2Verifying the Cluster#
Let’s verify that our cluster is set up correctly:
1kubectl get nodesYou should see output similar to this:
1NAME STATUS ROLES AGE VERSION2cka-cluster2-control-plane Ready control-plane 5m v1.30.03cka-cluster2-worker Ready <none> 4m30s v1.30.04cka-cluster2-worker2 Ready <none> 4m30s v1.30.05cka-cluster2-worker3 Ready <none> 4m30s v1.30.0Verifying Nodes as Docker Containers#
Remember, in KIND, each “node” is actually a Docker container. We can verify this by running:
1docker psYou should see four containers running, corresponding to our Kubernetes nodes.
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#
- KIND (Kubernetes IN Docker) Documentation
- Kubernetes Official Documentation: Installing kubectl
- KIND: Quick Start Guide
- KIND: Configuration