Easy Home Lab Setup of KIND & MicroK8s
Tags: devops, k8s, microk8s, kind
Published: 2024-01-17 11:35:18

After installing [minikube](https://geekopsjab.blogspot.com/2023/12/my-kubernetes-lab-setup-using-vagrant.html) on my Ubuntu VM which is running in Vagrant, on top of my windows 10 desktop. I started to notice some performance issues which ended up with frequent minikube restarts and constant VM reboots. Then on the internet, I found another way or actually two ways to run my k8s cluster lab setup on my local virtual environment using KIND & MicroK8s, which i would like to share with the community. So the steps are as follows,
## So, what is KIND ?
KIND is a tool that allows you to run local Kubernetes clusters using Docker container “nodes”. It is primarily designed for testing Kubernetes itself, but it can also be used for local development or continuous integration (CI). With KIND, you can create a Kubernetes cluster within minutes. It supports multi-node (including high availability) clusters and building Kubernetes release builds from source.

First lets build our VM using Vagrant and Virtualbox, you can get the steps from [here](https://geekopsjab.blogspot.com/2023/12/my-kubernetes-lab-setup-using-vagrant.html).

### Setting up the Vagrant directory & file
Open your Powershell terminal, create a directory and initiate vagrant to generate boilerplate file called Vagrantfile, which will be the config file for your vagrant ubuntu VM.
```
> mkdir Ubuntu_20_04; cd Ubuntu_20_04; mkdir data

> vagrant init
```
![Init setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4oz9inevdgqt58jy0jnt.PNG)

![Init setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwp7tydnzzlgoumz30qr.PNG)

![Vagrant init](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqwfog1qv04qnjb0ytue.PNG)

Modify the Vagrantfile to get Ubuntu 20.04 and other necessary configurations as below

```

Vagrant.configure("2") do |config| #start of the config

    config.vm.box = "generic/ubuntu2004" #get ubuntu 20.04 generic image

    config.vm.synced_folder "./data", "/vagrant_data" #make a dir to share files between host & VM

    config.vm.network "private_network", ip: "192.168.33.10" #set the ip as private

    config.vm.provider "virtualbox" do |vb| #use virtualbox to provision the VM

        vb.gui = true #set GUI while starting the VM

        vb.memory = "8192" #set RAM for VM

        vb.cpus = 4 #set CPU count for VM

    end

end

```

Now start the vagrant VM
``` > vagrant up ```

![Vagrant up](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2i6j48imscaxkyegmyyu.PNG)

Login to the ubuntu VM as vagrant user
``` > vagrant ssh ```

![Vagrant ssh](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jtmdxas6l3bocllzqd27.PNG)
Lets get the requirements to run KIND (Kubernetes in Docker)
We need 2 components to run Kind in our virtual environment, as per official [documentation](https://kind.sigs.k8s.io/). first its golang & second is container engine (Docker or Podman)

To install golang, you can follow below steps
```
$ wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz

$ sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz

$ export PATH=$PATH:/usr/local/go/bin
```

![get go1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9b6spb2t6evkiah0u7y.PNG)

![get go2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/muhr5km5qwy6dpe4gj38.PNG)
Now, lets install Docker using below commands
```
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add 

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

$ sudo apt update

$ sudo apt install docker-ce docker-ce-cli containerd.io

$ sudo systemctl status docker

$ sudo usermod -aG docker $USER && newgrp docker
```

![get docker1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cuju2095zvbmmqzkxwek.PNG)

![get docker2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inpthuky3ja5sja5ovzf.PNG)

![get docker3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zyg7hs5s7dp8vwfjiwsd.PNG)

Now get Kind packages to create our K8s cluster
```
$ [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64

$ chmod +x ./kind

$ sudo mv ./kind /usr/local/bin/kind

$ kind create cluster
```

![get kind1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdm4r1pddx7oj3mkfhs2.PNG)

![get kind2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ia8zipp08lcshi3qm7d.PNG)

Now, we need Kubectl to interact with our cluster setup.
```
$ sudo apt-get install -y apt-transport-https ca-certificates curl

$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

$ echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

$ kubectl cluster-info --context kind-kind 
```

![kubectl1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5230prebwmh6hf8ukux.PNG)

![kubectl2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tallv1u3pcxu5zbek5d.PNG)

![kubectl3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xz4rvl5n28hvp5la1ol5.PNG)

Now we have our lab K8s setup using Kind, which we can use to test & learn K8s. To delete the setup we can use the below command.

``` $ kind delete cluster ```

![kind4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf7qkldph0u5oo3tc4t6.PNG)

If you are bored with single node cluster, we have provision to create a multinode cluster in Kind using a config.yaml file, like below example

``` $ vim kind-config.yaml ```

```

kind: Cluster

apiVersion: kind.x-k8s.io/v1alpha4

nodes:

- role: control-plane

- role: worker

- role: worker

```

``` $ kind create cluster --config kind-config.yaml ```


![kind5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ws69qvav1x42wgjq8bds.PNG)

![kind6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dw6nzc439uldera0hw87.PNG)

So, This is how you can setup your local K8s cluster using Kind.

If you are lazy like me and don't want to perform such monotonous steps to get things work, we have alternate solution as well.

## Say hello to MicroK8s
MicroK8s is a lightweight, pure-upstream Kubernetes distribution that aims to reduce entry barriers for Kubernetes and cloud-native application development. It is designed to provide a full Kubernetes experience for devices with limited computing power and memory. With MicroK8s, you can install a single-node (standalone) Kubernetes cluster in under 60 seconds. It comes in a single package that installs a barebones upstream Kubernetes. Additional services like DNS and the Kubernetes dashboard can be enabled using the "microk8s enable" command.

MicroK8s supports multi-node clusters, high availability, and distributed storage. It also provides self-healing high availability, transactional over-the-air updates, and secure sandboxed kubelet environments.

Lets see how we can install MicroK8s in our Ubuntu VM

```
$ sudo snap install microk8s --classic

$ sudo usermod -a -G microk8s $USER && newgrp microk8s

$ microk8s status --wait-ready

$ microk8s kubectl get all --all-namespaces

```

![mk8s1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxphzv7yg4zop9i3bnig.PNG)

![mk8s2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ipz6u9pio2s4zknsxnd.PNG)

We can enable a dashboard to view and manage our K8s cluster running in MicroK8s, using

``` $ microk8s dashboard-proxy ```

![mk8s3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk1u3jspp3ck7eoqn95k.PNG)
Supply the generated login token on your localhost URL in our case its "https://192.168.33.10:10433"


![mk8s4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7k80bpftq4brqu2mx527.PNG)

![mk8s5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9td4275kpk8hazciye6.PNG)

And this is how the GUI dashboard will look like,

``` $ microk8s stop ```

![mk8s6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkny6w0rdhr7pmtexzug.PNG)

So, that's all folks. Do try to setup your local K8s environment and let me know your thoughts. As always, Thanks for reading...!