---
# System prepended metadata

title: Use 'kind' to setup local k8s
tags: [kubernetes]

---

# Use 'kind' to setup local k8s

###### tags: `kubernetes`

The "kind" is a tool to run local Kubernetes clusters using Docker container "nodes".


#### environment
> OS: ubuntu 20.04
> 2 vCPU, 4GB RAM
> IP 192.168.122.60/24
> use "root" user to install and setup

#### install docker
```
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ bash ./get-docker.sh 

$ docker -v
Docker version 20.10.16, build aa7e414
```

#### install golang version 1.17+
```
$ wget -L "https://go.dev/dl/go1.18.2.linux-amd64.tar.gz"

# get checksum
$ curl -sL https://golang.org/dl/ | grep -A 5 -w "go1.18.2.linux-amd64.tar.gz"
```

```
$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz
```
```
$ export PATH=$PATH:/usr/local/go/bin
$ go version
go version go1.18.2 linux/amd64
```

#### install kind and create cluster
```
$ go install sigs.k8s.io/kind@v0.14.0

$ go/bin/kind version
kind v0.14.0 go1.18.2 linux/amd64
```

#### create cluster
```
$ go/bin/kind create cluster
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.24.0) 🖼 
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Have a nice day! 👋
```
```
root@k8s-docker:~# docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED              STATUS              PORTS                       NAMES
479c7469a5da   kindest/node:v1.24.0   "/usr/local/bin/entr…"   About a minute ago   Up About a minute   127.0.0.1:45053->6443/tcp   kind-control-plan
```
delete the cluster
```
$ go/bin/kind delete cluster
```

#### create cluster with config file
create config.yaml file
```
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: yujung-cluster
networking:
  ipFamily: ipv4
  apiServerAddress: 192.168.122.60
  apiServerPort: 6443
  podSubnet: "10.244.0.0/16"
  serviceSubnet: "10.96.0.0/12"
  #disableDefaultCNI: true
  #kubeProxyMode: "ipvs"
nodes:
- role: control-plane
  extraMounts:
  - hostPath: /mnt/data
    containerPath: /mnt/data
    readOnly: false
    selinuxRelabel: false
    propagation: HostToContainer
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    listenAddress: 0.0.0.0
    protocol: TCP
- role: worker
- role: worker
- role: worker
```
```
root@k8s-docker:~# go/bin/kind create cluster --image kindest/node:v1.23.5 --config config.yaml 
Creating cluster "yujung-cluster" ...
 ✓ Ensuring node image (kindest/node:v1.23.5) 🖼 
 ✓ Preparing nodes 📦 📦 📦 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Joining worker nodes 🚜 
Set kubectl context to "kind-yujung-cluster"
You can now use your cluster with:

kubectl cluster-info --context kind-yujung-cluster

Thanks for using kind! 😊

root@k8s-docker:~# docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS         PORTS                                               NAMES
fdb08f800ed5   kindest/node:v1.24.0   "/usr/local/bin/entr…"   4 minutes ago   Up 3 minutes   0.0.0.0:80->80/tcp, 192.168.122.60:6443->6443/tcp   yujung-cluster-control-plane
d328ff76f920   kindest/node:v1.24.0   "/usr/local/bin/entr…"   4 minutes ago   Up 3 minutes                                                       yujung-cluster-worker2
c018cca53519   kindest/node:v1.24.0   "/usr/local/bin/entr…"   4 minutes ago   Up 3 minutes                                                       yujung-cluster-worker
5ac28bae665f   kindest/node:v1.24.0   "/usr/local/bin/entr…"   4 minutes ago   Up 3 minutes                                                       yujung-cluster-worker3
```

#### install kubectl
```
$ curl -LO https://dl.k8s.io/release/v1.23.5/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ mv ./kubectl /usr/local/bin/
```
```
$ kubectl get node
NAME                           STATUS   ROLES                  AGE    VERSION
yujung-cluster-control-plane   Ready    control-plane,master   149m   v1.23.5
yujung-cluster-worker          Ready    <none>                 148m   v1.23.5
yujung-cluster-worker2         Ready    <none>                 148m   v1.23.5
yujung-cluster-worker3         Ready    <none>                 148m   v1.23.5

```

#### install helm
```
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3

$ chmod 700 ./get_helm.sh

$ ./get_helm.sh
Downloading https://get.helm.sh/helm-v3.9.0-linux-amd64.tar.gz
Verifying checksum... Done.
Preparing to install helm into /usr/local/bin
helm installed into /usr/local/bin/helm
```
```
$ helm version
version.BuildInfo{Version:"v3.9.0", GitCommit:"7ceeda6c585217a19a1131663d8cd1f7d641b2a7", GitTreeState:"clean", GoVersion:"go1.17.5"}
```

#### install prometheus, alertmanager, grafana using helm (draft)
download config yaml (for reference, not use it now)
```
$ wget https://raw.githubusercontent.com/prometheus-community/helm-charts/main/charts/kube-prometheus-stack/values.yaml
```

installation
```
$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo add stable https://charts.helm.sh/stable

$ helm install prometheus prometheus-community/kube-prometheus-stack --debug

output omit....

NOTES:
kube-prometheus-stack has been installed. Check its status by running:
  kubectl --namespace default get pods -l "release=prometheus"

Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.
```

```
root@k8s-docker:~# kubectl get pod
NAME                                                     READY   STATUS    RESTARTS   AGE
alertmanager-prometheus-kube-prometheus-alertmanager-0   2/2     Running   0          120m
prometheus-grafana-5f8bd7db76-frbhs                      3/3     Running   0          120m
prometheus-kube-prometheus-operator-6794f987b-tjknh      1/1     Running   0          120m
prometheus-kube-state-metrics-94f76f559-xxdvk            1/1     Running   0          120m
prometheus-prometheus-kube-prometheus-prometheus-0       2/2     Running   0          119m
prometheus-prometheus-node-exporter-5srpm                1/1     Running   0          120m
prometheus-prometheus-node-exporter-86bcd                1/1     Running   0          120m
prometheus-prometheus-node-exporter-gdk2g                1/1     Running   0          120m
prometheus-prometheus-node-exporter-p9s92                1/1     Running   0          120m
```

```
$ kubectl port-forward deployment/prometheus-grafana 3000 --address 0.0.0.0

$ kubectl port-forward svc/prometheus-kube-prometheus-prometheus 9090 --address 0.0.0.0

$ kubectl port-forward svc/prometheus-kube-prometheus-alertmanager 9093 --address 0.0.0.0
```




https://k21academy.com/docker-kubernetes/prometheus-grafana-monitoring/


#### reference
https://kind.sigs.k8s.io/
https://github.com/kubernetes-sigs/kind

https://www.cyberciti.biz/faq/how-to-install-gol-ang-on-ubuntu-linux/
https://go.dev/doc/install

https://helm.sh/docs/intro/install/

https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml