DEV Community

Cover image for kind - Creating Clusters using Configuration File - Part 3
Unni P
Unni P

Posted on โ€ข Originally published at iamunnip.hashnode.dev

kind - Creating Clusters using Configuration File - Part 3

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

$ cat kind.yml
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
name: dev
nodes:
- role: control-plane
- role: worker
- role: worker
Enter fullscreen mode Exit fullscreen mode
$ 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
Enter fullscreen mode Exit fullscreen mode
$ 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
Enter fullscreen mode Exit fullscreen mode

HA Cluster

Creating a cluster having multiple control planes for high availability

$ 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
Enter fullscreen mode Exit fullscreen mode
$ 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
Enter fullscreen mode Exit fullscreen mode
$ 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
Enter fullscreen mode Exit fullscreen mode

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

$ 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
Enter fullscreen mode Exit fullscreen mode
$ 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
Enter fullscreen mode Exit fullscreen mode
$ 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
Enter fullscreen mode Exit fullscreen mode

Cleanup

Delete the cluster after use

$ kind delete cluster --name dev
Deleting cluster "dev" ...
Deleted nodes: ["dev-worker2" "dev-worker" "dev-control-plane"]
Enter fullscreen mode Exit fullscreen mode

Reference

https://kind.sigs.k8s.io/

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)