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:

  1. Install kubectl

  2. Install KIND

Creating a Single-Node Cluster:

  1. Create the cluster:

     kind create cluster --image kindest/node:v1.29.4@sha256:3abb816a5b1061fb15c6e9e60856ec40d56b7b52bcea5f5f1350bc6e2320b6f8 --name cluster-1
    
  2. Get cluster info:

     kubectl cluster-info --context kind-cluster-1
    
  3. 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)

  1. Create a config.yaml file defining the cluster structure

  2. Config file contents:

     # three node (two workers) cluster config
     kind: Cluster
     apiVersion: kind.x-k8s.io/v1alpha4
     nodes:
     - role: control-plane
     - role: worker
     - role: worker
    
  3. 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
    
  4. 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

1
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!