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
-
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.
-
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
-
Install
kubectl
(if not already installed): To interact with the Kubernetes cluster, you need to havekubectl
installed. If you haven't installed it yet, use the following command:sudo snap install kubectl --classic
-
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
-
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>
- To create the default cluster:
-
Delete a Cluster:
- To delete the default cluster:
kind delete cluster
- To delete a specific cluster by name:
kind delete cluster --name <cluster-name>
- To delete the default cluster:
-
List Clusters: To list all running
kind
clusters:kind get clusters
-
Interact with a Specific Cluster: If you have multiple
kind
clusters, you can interact with a specific cluster by setting the appropriate context inkubectl
: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.
-
Create Multiple Clusters: To create multiple clusters, assign unique names to each cluster:
kind create cluster --name cluster1 kind create cluster --name cluster2
-
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
-
Delete Specific Clusters: To delete an individual cluster, specify the name of the cluster:
kind delete cluster --name cluster1 kind delete cluster --name cluster2
-
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.