Building a Kind Kubernetes Cluster on Linux: A Comprehensive Guide

Photo by Growtika on Unsplash

Building a Kind Kubernetes Cluster on Linux: A Comprehensive Guide

Simplifying Kubernetes on Linux with Kind: A Step-by-Step Guide to Creating a Lightweight Cluster

Kubernetes has become the de facto standard for container orchestration, allowing developers to easily manage and scale their applications. Setting up a Kubernetes cluster on Linux can seem daunting at first, but fear not! In this blog post, we will explore how to create a Kind Kubernetes cluster, a lightweight and user-friendly option for local development and testing purposes. Let's dive in and discover the power of Kind on Linux!

Understanding Kind Kubernetes:

Kind (Kubernetes in Docker) is an open-source tool that provides a simple and efficient way to run Kubernetes clusters using Docker containers. It creates a lightweight Kubernetes environment, ideal for local development, CI/CD pipelines, and testing scenarios. Kind clusters are ephemeral, making them easy to create, destroy, and recreate as needed.

Comparison with other options for a local kubernetes setup

ToolAdvantagesDisadvantages
Kind- Lightweight and fast- Limited to running clusters with Docker containers as nodes
K3s- Lightweight and resource-efficient- Some features and components may be stripped down or not available compared to full Kubernetes
MicroK8s- Easy installation and setup- Primarily designed for Linux, limited macOS and Windows support
Docker Desktop- Integrated with Docker ecosystem- Limited to macOS and Windows operating systems

Prerequisites:

Docker:

    • Install the latest version of Docker on your Linux system

      •     sudo apt update
            sudo apt install apt-transport-https ca-certificates curl software-properties-common
            curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
            echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
            sudo apt update
            apt-cache policy docker-ce
            sudo apt install docker-ce
        

        Post verification steps

      • sudo systemctl status docker

        •     docker.service - Docker Application Container Engine
                   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
                   Active: active (running) since Fri 2022-04-01 21:30:25 UTC; 22s ago
              TriggeredBy: ● docker.socket
                     Docs: https://docs.docker.com
                 Main PID: 7854 (dockerd)
                    Tasks: 7
                   Memory: 38.3M
                      CPU: 340ms
                   CGroup: /system.slice/docker.service
                           └─7854 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
          

kubectl

    •       curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
            chmod +x kubectl
            mv ./kubectl /usr/local/bin/kubectl
            kubectl version --client
      

Kind

    • Install the Kind CLI tool, which enables the creation and management of Kind clusters

      •     curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
        
            chmod +x ./kind
            mv ./kind /usr/local/bin
            which kind
        

        Post verification steps
        kind version

  • Creating a Kind Kubernetes Cluster:
    Now that you have all the prerequisites in place, it's time to create your Kind Kubernetes cluster. Use the following command to create a cluster named "my-cluster":
    kind create cluster --name my-cluster

    • This command will download the required Kubernetes images, create Docker containers for the control plane and worker nodes, and configure kubectl to communicate with the cluster
  • Delete the cluster

    • kind delete cluster --name my-cluster
  • Now let's create three nodes (two workers) cluster config with Kind

    • Create the configuration file [threenode.yaml]

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

        
          [root@node1 ~]# kubectl get nodes
          NAME               STATUS  ROLES         AGE   VERSION
          kind-control-plane  Ready  control-plane,master  1m26s  v1.21.11
          kind-worker         Ready  <none>                1m24s  v1.21.11
          kind-worker         Ready  <none>                1m24s  v1.21.11
        

Thus creating a Kind Kubernetes cluster on Linux is a straightforward process that allows you to have a lightweight and easy-to-use Kubernetes environment for local development and testing. By following the steps outlined in