Day 6/40
Kubernetes Multi Node Cluster Setup Step By Step - Kind
Video Link
@piyushsachdeva
Git Repository
My Git Repo
There are many ways to install the Kubernetes
such as installing with Minikube
, MicroK8s
, K3s
and Kubeadm
, but in this section, we're going to install it with Kind
cluster.
Read More: Link1, Link2
kind is a tool for running local Kubernetes clusters using Docker container “nodes”.
kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.
Installation Process
1. Prerequisite
Golang is needed at first
root@localhost:~# apt install golang -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
golang is already the newest version (2:1.18~0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.
2. Download kind
on linux
root@localhost:~# [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 98 100 98 0 0 1080 0 --:--:-- --:--:-- --:--:-- 1088
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 6381k 100 6381k 0 0 6188k 0 0:00:01 0:00:01 --:--:-- 6188k
root@localhost:~# chmod +x kind
root@localhost:~# mv kind /usr/local/bin/kind
root@localhost:~# kind --version
kind version 0.23.0
3. Installing kubectl
root@localhost:~# curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 138 100 138 0 0 752 0 --:--:-- --:--:-- --:--:-- 754
100 49.0M 100 49.0M 0 0 53.0M 0 --:--:-- --:--:-- --:--:-- 53.0M
root@localhost:~# curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 138 100 138 0 0 728 0 --:--:-- --:--:-- --:--:-- 730
100 64 100 64 0 0 240 0 --:--:-- --:--:-- --:--:-- 240
root@localhost:~# echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
kubectl: OK
root@localhost:~# sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
root@localhost:~# kubectl version
Client Version: v1.30.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.4
4. Creating a Cluster
Please read the Release Notes
root@localhost:~# kind create cluster --image kindest/node:v1.29.4@sha256:3abb816a5b1061fb15c6e9e60856ec40d56b7b52bcea5f5f1350bc6e2320b6f8 --name jolly-jumper
Creating cluster "jolly-jumper" ...
✓ Ensuring node image (kindest/node:v1.29.4) 🖼
✓ Preparing nodes 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
Set kubectl context to "kind-jolly-jumper"
You can now use your cluster with:
kubectl cluster-info --context kind-jolly-jumper
Thanks for using kind! 😊
root@localhost:~# kubectl cluster-info --context kind-jolly-jumper
Kubernetes control plane is running at https://127.0.0.1:46167
CoreDNS is running at https://127.0.0.1:46167/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
5. Interact with the clsuter
root@localhost:~# kind get clusters
jolly-jumper
root@localhost:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
jolly-jumper-control-plane Ready control-plane 112s v1.29.4
root@localhost:~# kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kind-jolly-jumper kind-jolly-jumper kind-jolly-jumper
6. Configuring a multi-nodes kind
cluster
yaml file with 3 nodes for instance. Find more
# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
root@localhost:~# kind create cluster --name lucky-luke --config kind-lucky-luke.yaml
Creating cluster "lucky-luke" ...
✓ Ensuring node image (kindest/node:v1.30.0) 🖼
✓ Preparing nodes 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-lucky-luke"
You can now use your cluster with:
kubectl cluster-info --context kind-lucky-luke
Not sure what to do next? 😅 Check out https://kind.sigs.k8s.io/docs/user/quick-start/
root@localhost:~# kind get clusters
jolly-jumper
lucky-luke
Note
Important website for exam:
7. Switching between contexts
root@localhost:~# kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
kind-jolly-jumper kind-jolly-jumper kind-jolly-jumper
* kind-lucky-luke kind-lucky-luke kind-lucky-luke
root@localhost:~# kubectl config current-context
kind-lucky-luke
root@localhost:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
lucky-luke-control-plane Ready control-plane 4m36s v1.30.0
lucky-luke-worker NotReady <none> 3m40s v1.30.0
lucky-luke-worker2 NotReady <none> 3m26s v1.30.0
root@localhost:~# kubectl config use kind-jolly-jumper
Switched to context "kind-jolly-jumper".
root@localhost:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
jolly-jumper-control-plane Ready control-plane 10m v1.29.4