DEV Community

Cover image for Development cluster with kind
Ashok Nagaraj
Ashok Nagaraj

Posted on • Edited on

Development cluster with kind

Minikube is great but is resource intensive. It has lots of customization options. One can choose between a VM and a Docker container for running a machine, choose from different container runtimes, and more.
Advantages

  • Can run multiple versions of kubernetes
  • Full featured kubernetes
  • Supports local registries with no authorization overheads
  • Lots of documentation and tutorials

Disadvantages

  • Resource heavy (drains my battery in about an hour)
  • One needs to dig-in to customize based on myriad of options

Kind runs kubernetes inside a docker container. Even the kubernetes team uses Kind to test kubernetes itself.

Pros

  • Light weight clusters
  • Super speedy cluster creation (< 1minute)
  • Uses containerd instead of docker-shim
  • Supports sufficient customization

Kind setup
Install kind cli

Configuration
The below configuration is used to create single master, two worker node cluster with ingress enabled. It also exposes ports 80, 443 and 30000 (mapped transparently to localhost).

Note: 30000 can be used for NodePort (check the link below)

❯ cat ${HOME}/kind-config.yaml
# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 30000
    hostPort: 30000
    listenAddress: "0.0.0.0"
    protocol: TCP
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP
- role: worker
- role: worker
Enter fullscreen mode Exit fullscreen mode

Create the cluster

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

kubectl cluster-info --context kind-macbook

Thanks for using kind! 😊

❯ kubectl get nodes
NAME                    STATUS   ROLES                  AGE   VERSION
macbook-control-plane   Ready    control-plane,master   11d   v1.21.1
macbook-worker          Ready    <none>                 11d   v1.21.1
macbook-worker2         Ready    <none>                 11d   v1.21.1
Enter fullscreen mode Exit fullscreen mode

Create a pod

❯ kubectl run nginx --image=nginx --port=80 --restart=Never
pod/nginx created

❯ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE   LABELS
nginx   1/1     Running   0          63s   run=nginx
Enter fullscreen mode Exit fullscreen mode

Expose the pod as a service

❯ kubectl expose pod/nginx --port=80
service/nginx exposed
❯ kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP   11d
nginx        ClusterIP   10.96.54.47   <none>        80/TCP    3s
❯ kubectl port-forward svc/nginx 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
...
Enter fullscreen mode Exit fullscreen mode

Check the working
Open http://localhost:8080/. You should see the Welcome to nginx page.

Delete the cluster

❯ kind delete cluster --name=macbook
Deleting cluster "macbook" ...

Enter fullscreen mode Exit fullscreen mode

Try more things ...

Top comments (0)