Day 06/40 Days of K8s: KIND Multi-Node cluster Setup locally.
Before diving into managed Kubernetes services on the cloud, it's crucial to set up and manage own cluster locally. This hands-on approach allows us to better understand all components, especially the control plane, and gain valuable experience in troubleshooting and debugging.
KIND (Kubernetes In Docker)creates all nodes as docker container, light-weight to run and multi-node Kubernetes environment for local development and testing.
Prerequisites:
Install kubectl
Install KIND
Creating a Single-Node Cluster:
Create the cluster:
kind create cluster --image kindest/node:v1.29.4@sha256:3abb816a5b1061fb15c6e9e60856ec40d56b7b52bcea5f5f1350bc6e2320b6f8 --name cluster-1
Get cluster info:
kubectl cluster-info --context kind-cluster-1
Check current context:
kubectl config current-context
Note: All requests from client go to the API server, which retrieves data from etcd and returns the output.
Creating a Multi-Node Cluster (1 Control Plane, 2 Workers)
Create a
config.yaml
file defining the cluster structureConfig file contents:
# three node (two workers) cluster config kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker - role: worker
Create the cluster using the config file:
kind create cluster --image kindest/node:v1.29.4@sha256:3abb816a5b1061fb15c6e9e60856ec40d56b7b52bcea5f5f1350bc6e2320b6f8 --name kind-cluster-2 --config config.yaml
Workers are automatically joined to the control plane.
Managing Cluster Contexts
View current context:
kubectl config current-context
Switch context:
kubectl config use-context kind-cluster-1
List all contexts:
kubectl config get-contexts
Kubectl config set-context: It is used to create a new context or modify an existing one in the context-list.
kubectl config use-context: It is used for switching to an already existing context.
This provides a clear overview of the process, separating the single-node and multi-node cluster setups, and including managing cluster contexts.
๐ IMPORTANT: It's critical to ensure you're working on the correct cluster context at all times. Operating on the wrong context can lead to unintended changes in the wrong cluster.
#Kubernetes #KIND #OneNodeCluster #MultiNodeCluster #40DaysofKubernetes #CKASeries
Subscribe to my newsletter
Read articles from Gopi Vivek Manne directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Gopi Vivek Manne
Gopi Vivek Manne
I'm Gopi Vivek Manne, a passionate DevOps Cloud Engineer with a strong focus on AWS cloud migrations. I have expertise in a range of technologies, including AWS, Linux, Jenkins, Bitbucket, GitHub Actions, Terraform, Docker, Kubernetes, Ansible, SonarQube, JUnit, AppScan, Prometheus, Grafana, Zabbix, and container orchestration. I'm constantly learning and exploring new ways to optimize and automate workflows, and I enjoy sharing my experiences and knowledge with others in the tech community. Follow me for insights, tips, and best practices on all things DevOps and cloud engineering!