After installing minikube 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.
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
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
Login to the ubuntu VM as vagrant user
> vagrant ssh
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. 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
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
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
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
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
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
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
We can enable a dashboard to view and manage our K8s cluster running in MicroK8s, using
$ microk8s dashboard-proxy
Supply the generated login token on your localhost URL in our case its "https://192.168.33.10:10433"
And this is how the GUI dashboard will look like,
$ microk8s stop
So, that's all folks. Do try to setup your local K8s environment and let me know your thoughts. As always, Thanks for reading...!
Top comments (0)