Kubernetes
Setup Cluster
Kind-K8S
Clustersetup

Kubernetes Cluster Setup with kind

kind (Kubernetes IN Docker) is a tool for running Kubernetes clusters locally using Docker containers. It is ideal for testing and development environments.


Step 3: Create a Kubernetes Cluster with kind

  1. Create a Kubernetes Cluster: To create a default Kubernetes cluster with a single node using kind, run the following command:

    kind create cluster

    This command sets up a Kubernetes cluster running within Docker containers.

  2. Create a Cluster with a Specific Name: If you want to create a cluster with a custom name, use the --name flag:

    kind create cluster --name <cluster-name>

Step 4: Verify the Cluster

  1. Install kubectl (if not already installed): To interact with the Kubernetes cluster, you need to have kubectl installed. If you haven't installed it yet, use the following command:

    sudo snap install kubectl --classic
  2. Verify the Cluster is Running: After creating the cluster, verify that the cluster is running and accessible:

    kubectl cluster-info --context kind-kind

Basic kind Commands

  1. Create a Cluster:

    • To create the default cluster:
      kind create cluster
    • To create a cluster with a custom name:
      kind create cluster --name <cluster-name>
  2. Delete a Cluster:

    • To delete the default cluster:
      kind delete cluster
    • To delete a specific cluster by name:
      kind delete cluster --name <cluster-name>
  3. List Clusters: To list all running kind clusters:

    kind get clusters
  4. Interact with a Specific Cluster: If you have multiple kind clusters, you can interact with a specific cluster by setting the appropriate context in kubectl:

    kubectl cluster-info --context kind-<cluster-name>

Creating a Multi-Node Cluster

To create a multi-node cluster (with multiple control plane or worker nodes), you need to define a custom configuration file.

Example YAML for a Multi-Node Cluster:

# multi-node-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: worker
  - role: worker

Alternatively, you can specify the Kubernetes node images you want to use:

# kind create cluster --config kind-cluster-1M-3W-v1.30.yaml --name  chat-prod
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    image: kindest/node:v1.30.4
  - role: worker
    image: kindest/node:v1.30.4
  - role: worker
    image: kindest/node:v1.30.4
  - role: worker
    image: kindest/node:v1.30.4
# multi-node-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    image: kindest/node:v1.30.4@sha256:976ea815844d5fa93be213437e3ff5754cd599b040946b5cca43ca45c2047114
  - role: worker
    image: kindest/node:v1.29.4@sha256:d46b7aa29567e93b27f7531d258c372e829d7224b25e3fc6ffdefed12476d3aa
  - role: worker
    image: kindest/node:v1.30.4@sha256:d46b7aa29567e93b27f7531d258c372e829d7224b25e3fc6ffdefed12476d3aa

Create the Multi-Node Cluster:

Use the above YAML configuration to create a multi-node cluster:

kind create cluster --config multi-node-config.yaml --name <cluster-name>

Creating a Multi-Cluster Setup

With kind, you can set up multiple clusters on your local system, each with its own separate context.

  1. Create Multiple Clusters: To create multiple clusters, assign unique names to each cluster:

    kind create cluster --name cluster1
    kind create cluster --name cluster2
  2. Switch Between Clusters: You can switch between clusters by using the appropriate context with kubectl:

    kubectl cluster-info --context kind-cluster1
    kubectl cluster-info --context kind-cluster2
  3. Delete Specific Clusters: To delete an individual cluster, specify the name of the cluster:

    kind delete cluster --name cluster1
    kind delete cluster --name cluster2
  4. BONUS: Advance Cluster Mgmt cmds:

    kind get clusters
    kind delete cluster --name <cluster-name>
    kind delete clusters --all

    Advance Public Access of kind-k8 object cmds:

    kubectl port-forward pod/nginx-<pod-id> 8080:80 --address 0.0.0.0
    curl http://<ec2-public-ip>:8080

This document provides the steps and commands to set up, manage, and delete Kubernetes clusters using kind, whether it's a single-node, multi-node, or multi-cluster setup.


🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!