DEV Community

Hyo
Hyo

Posted on

Setup local k8s cluster using kind

In k8s world, there is a need for testing before going production. One among them is using kind to build local cluster.
There are many ways in official document, here is my prefer way using yaml to define my expectation.

Creating a yaml file named kind.yaml as below to configure 1 master and 2 workers:

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
  image: kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047
  extraPortMappings:
  - containerPort: 30778
    hostPort: 30778
    listenAddress: "0.0.0.0"
    protocol: tcp
- role: worker
  image: kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047
- role: worker
  image: kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047 
Enter fullscreen mode Exit fullscreen mode

Install kind if not have. If you're using MacOS, run: brew install kind for package manager using brewk

Run command to setup cluster: kind create cluster --name local --config kind.yaml

Here is my result, tested in Mac M1 chip:

kind create cluster --name local --config kind.yaml
Creating cluster "local" ...
 ✓ Ensuring node image (kindest/node:v1.22.0) đŸ–ŧ 
 ✓ Preparing nodes đŸ“Ļ đŸ“Ļ đŸ“Ļ  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹ī¸ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Joining worker nodes 🚜 
Set kubectl context to "kind-local"
You can now use your cluster with:

kubectl cluster-info --context kind-local

Have a nice day! 👋
Enter fullscreen mode Exit fullscreen mode

With k8s contents as below:

kubectl config set-context local-kind                                           Context "local-kind" created.

kubectl get node                                                                  
NAME                  STATUS   ROLES                  AGE     VERSION
local-control-plane   Ready    control-plane,master   7m58s   v1.22.0
local-worker          Ready    <none>                 7m26s   v1.22.0
local-worker2         Ready    <none>                 7m26s   v1.22.0
Enter fullscreen mode Exit fullscreen mode

Top comments (0)