kind - Creating Clusters using Configuration File - Part 3
Tags: opensource, docker, kubernetes, devops
Published: 2023-05-03 07:28:16

> In this article we will look how we can configure our kind cluster in a declarative way

## Introduction

* kind cluster can be created and configured in a declarative way
    
* We can define our desired state for kind cluster in a YAML file
    
* YAML file follows Kubernetes conventions and versioning
    
* Parameters passed in the CLI take precedence over their equivalent in the config file
    

## Usage

### Simple Cluster

Creating a simple cluster having one control plane and two worker nodes

```bash
$ cat kind.yml
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
name: dev
nodes:
- role: control-plane
- role: worker
- role: worker
```

```bash
$ kind create cluster --config kind.yml 
Creating cluster "dev" ...
 ✓ Ensuring node image (kindest/node:v1.26.3) 🖼
 ✓ Preparing nodes 📦 📦 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Joining worker nodes 🚜 
Set kubectl context to "kind-dev"
You can now use your cluster with:

kubectl cluster-info --context kind-dev
```

```bash
$ kubectl get nodes 
NAME                STATUS   ROLES           AGE   VERSION
dev-control-plane   Ready    control-plane   53s   v1.26.3
dev-worker          Ready    <none>          16s   v1.26.3
dev-worker2         Ready    <none>          29s   v1.26.3
```

### HA Cluster

Creating a cluster having multiple control planes for high availability

```bash
$ cat kind.yml 
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
name: dev
nodes:
- role: control-plane
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker
```

```bash
$ kind create cluster --config kind.yml 
Creating cluster "dev" ...
 ✓ Ensuring node image (kindest/node:v1.26.3) 🖼
 ✓ Preparing nodes 📦 📦 📦 📦 📦 📦  
 ✓ Configuring the external load balancer ⚖️ 
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Joining more control-plane nodes 🎮 
 ✓ Joining worker nodes 🚜 
Set kubectl context to "kind-dev"
You can now use your cluster with:

kubectl cluster-info --context kind-dev
```

```bash
$ kubectl get nodes
NAME                 STATUS   ROLES           AGE     VERSION
dev-control-plane    Ready    control-plane   2m32s   v1.26.3
dev-control-plane2   Ready    control-plane   2m18s   v1.26.3
dev-control-plane3   Ready    control-plane   74s     v1.26.3
dev-worker           Ready    <none>          56s     v1.26.3
dev-worker2          Ready    <none>          56s     v1.26.3
dev-worker3          Ready    <none>          68s     v1.26.3
```

### Changing Kubernetes Version

We can change the Kubernetes version by setting the node’s container image and it’s mandatory to include the sha256 value with the image

```bash
$ cat kind.yml
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
name: dev
nodes:
- role: control-plane
  image: kindest/node:v1.27.0@sha256:c6b22e613523b1af67d4bc8a0c38a4c3ea3a2b8fbc5b367ae36345c9cb844518
- role: worker
  image: kindest/node:v1.27.0@sha256:c6b22e613523b1af67d4bc8a0c38a4c3ea3a2b8fbc5b367ae36345c9cb844518
- role: worker
  image: kindest/node:v1.27.0@sha256:c6b22e613523b1af67d4bc8a0c38a4c3ea3a2b8fbc5b367ae36345c9cb844518
```

```bash
$ kind create cluster --config kind.yml 
Creating cluster "dev" ...
 ✓ Ensuring node image (kindest/node:v1.27.0) 🖼 
 ✓ Preparing nodes 📦 📦 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Joining worker nodes 🚜 
Set kubectl context to "kind-dev"
You can now use your cluster with:

kubectl cluster-info --context kind-dev
```

```bash
$ kubectl get nodes
NAME                STATUS   ROLES           AGE   VERSION
dev-control-plane   Ready    control-plane   61s   v1.27.0
dev-worker          Ready    <none>          42s   v1.27.0
dev-worker2         Ready    <none>          41s   v1.27.0
```

## Cleanup

Delete the cluster after use

```bash
$ kind delete cluster --name dev
Deleting cluster "dev" ...
Deleted nodes: ["dev-worker2" "dev-worker" "dev-control-plane"]
```

## Reference

[https://kind.sigs.k8s.io/](https://kind.sigs.k8s.io/)