Step-by-Step Kubernetes Multinode Setup: Day 6 of 40daysofkubernetes

Step-by-Step Kubernetes Multinode Setup: Day 6 of 40daysofkubernetes

Introduction

For learning and practicing Kubernetes, we have multiple ways to set up a Kubernetes cluster like Minikube, K3D, Kind, GetDeck, etc. All of these tools are capable of providing a developer with a dedicated Kubernetes environment for learning, playing around, or solving development problems.

In this 40 days of Kubernetes series, we will use Kind.

Kind is a tool for running local Kubernetes clusters using Docker container “nodes”. It was primarily designed for testing Kubernetes itself but may be used for local development or CI.

Note: For installing Kind, your machine must have Docker installed.

Installation

If you are a go developer you may find the go install option convenient.

Installing From Release Binaries:

On Linux:

# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

On macOs:

# For Intel Macs
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-darwin-amd64
# For M1 / ARM Macs
[ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-darwin-arm64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind

On windows in PowerShell:

curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.23.0/kind-windows-amd64
Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe

For further installation guide, u can refer this guide.

You can verify the installation by checking the Kind version with: kind version command.

Creating a single node cluster

kind create cluster will bootstrap a Kubernetes cluster using a pre-built node image. To specify the version of the image you want to install, you can use the --image flag and the --name flag for the cluster name.

By default, the control plane and worker plane are in the same node. However, in production, the control plane and worker plane are on different nodes. Therefore, we will create a multi-node cluster.

You can see your cluster is running by following command:

kubectl cluster-info --context cluster-name

kubectl is the command-line tool used to interact with Kubernetes clusters. It allows you to run commands against Kubernetes clusters to deploy applications, inspect and manage cluster resources, and view logs. Install kubectl if you haven't already.

You can check your nodes by following command:

kubectl get nodes

Creating a multi-node cluster

First, create a config.yaml file with the following command:

nano config.yaml
or 
vi config.yaml

Paste the below content into the file:

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

Now, use the same command kind create cluster with the --config flag to create the multi-node cluster:

Now check your nodes , by kubectl get nodes

In our cluster2, we have three nodes: one control plane and two worker nodes.

But why don't we see our cluster1? Because the kubectl command only shows the current cluster information.

To see cluster1 information, you have to switch to cluster1:

kubectl config get-contexts command shows all cluster in our local machine .

and by kubectl config use-context cluster-name u can switch to different clusters.

Note: As mentioned in the introduction, Kind uses Docker containers to run our nodes. You can verify this by running docker ps and in last U don't have to remmember all these commands u can use kubernetes cheatsheet for these commands.

Resources i used:

Video-

Docs-

Documentation