Setting up Kubernetes using KinD multi-node clusters

K8s kind (short for “Kubernetes in Docker”) is a tool that facilitates the running of local Kubernetes clusters using Docker containers as nodes. Designed primarily for testing Kubernetes itself, kind can also be used for local development and CI (continuous integration).

Prerequisites

1. Install Docker:

Install Docker on Ubantu

sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER #my case is ubuntu
systemctl restart docker

2. Install kubectl:

Install kubectl on Ubantu

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

4. Install go:

3. Install kind:

  • You can install kind using go, brew (on macOS), or download the binary directly. Here's how to install it using go:
go install sigs.k8s.io/kind@v0.23.0

Step-by-Step Setup

In particular, many users may be interested in multi-node clusters

1. Create a Kind Configuration File: Create a configuration file for your cluster. Let’s name it kind-config.yaml:

# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker

2. Create the Cluster: Use the kind command to create a cluster based on the configuration file:

kind create cluster --config kind-config.yaml

3. Set Up kubeconfig: Make sure your kubeconfig is set up to use the new kind cluster:

kind get kubeconfig --name kind > ~/.kube/config

4. Check Node Status: Verify that all nodes are up and running:

kubectl get nodes

You should see one control plane node and two worker nodes listed.

Deploy a Test Application: To ensure everything is working, deploy a simple application. For example, deploy an Nginx pod:

kubectl create deployment nginx --image=nginx kubectl expose deployment nginx --port=80 --type=NodePort

Access the Application: Find the NodePort assigned to your Nginx service:

kubectl get svc nginx

You can then access the application using the Node’s IP and the NodePort.

Additional Tips

  • Scaling the Cluster: If you need to add more worker nodes, you can edit the kind-config.yaml file to add more worker nodes and then recreate the cluster.

  • Deleting the Cluster: To delete the cluster, use:

kind delete cluster
  • Persistent Volumes: If your applications require persistent storage, you might need to configure persistent volumes. kind can use hostPath or other storage solutions.

Troubleshooting

Common Issues:

  • Docker Issues: Ensure Docker is running correctly and you can run Docker commands without issues.

  • Configuration Errors: Double-check your kind-config.yaml for syntax errors or misconfigurations.

  • Network Issues: Ensure there are no network conflicts on your machine that might prevent kind from setting up the cluster correctly.

Ref link: kind.sigs.k8s.io

It’s Done 👍