Development cluster with kind
Tags: kubernetes, beginners, productivity
Published: 2022-01-28 14:08:37

[Minikube](https://github.com/kubernetes/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](https://kind.sigs.k8s.io/docs/user/quick-start/) 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](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)

<u>Configuration</u>
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)

```bash
❯ 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
```

<u>Create the cluster</u>
```bash
❯ 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
```

<u>Create a pod</u>
```
❯ 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
```

<u>Expose the pod as a service</u>
```
❯ 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
...
```

<u>Check the working</u> 
Open [http://localhost:8080/](http://localhost:8080/). You should see the **Welcome to nginx** page.

<u>Delete the cluster</u>
```
❯ kind delete cluster --name=macbook
Deleting cluster "macbook" ...

```

---

Try more things ...

- [Ingress](https://kind.sigs.k8s.io/docs/user/ingress/)
- [LoadBalancer](https://kind.sigs.k8s.io/docs/user/loadbalancer/)
- [NodePort](https://stackoverflow.com/questions/62432961/how-to-use-nodeport-with-kind)