My Kubernetes Lab Setup - Using Vagrant & Docker
Tags: kubernetes, minikube, lab, setup
Published: 2023-12-29 06:15:01

My everyday driver is a Windows 10 PC, and today we will install minikube on Ubuntu 20.04 running as a Vagrant VM. I have already installed Hashicorp's Vagrant and Oracle VirtualBox on the PC to build up several environments for testing.

You may know more about Vagrant from [here](https://geekopsjab.blogspot.com/2023/12/exploring-vagrant-simplifying.html), and get both downloaded from here ([Vagrant](https://developer.hashicorp.com/vagrant/install), [VirtualBox](https://www.virtualbox.org/wiki/Downloads)). Post installing Vagrant & Virtualbox now time to get our Kubernetes lab setup up and running.

## What is Minikube ?
Minikube is an open-source tool that enables developers to easily set up and manage local Kubernetes clusters for development and testing purposes. By creating a single-node Kubernetes cluster within a virtual machine on the user's local machine, Minikube provides a convenient and isolated environment for simulating Kubernetes deployments. Its user-friendly command-line interface, compatibility with various virtualization drivers, and support for Kubernetes addons make Minikube an essential tool for developers looking to learn, experiment, and develop applications in a controlled Kubernetes environment without the need for a full-scale cluster.

## 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 ubuntu2004; cd ubuntu2004; mkdir data

> vagrant init
```

![vagrant-init](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqztdeo4stgax69s6ox3.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/f4tflj19s54yjzgi3ctd.PNG)
Login to the ubuntu VM as vagrant user ``` > vagrant ssh ```

![vagrant-ssh](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vdndeog25usr5croci3a.PNG)
## Installing Docker, Drivers & Minikube
Using below commands to install docker & drivers
```
~$ 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 
```

![get-docker-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/586z9tojhvju8higz2bq.PNG)

![get-docker-2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/027dbrkkz8boos7xvg8x.PNG)

![get-docker-3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf5qbtjo3hm36zjad95m.PNG)

Add the vagrant user under docker group to fix permissions further.
```
~$ sudo usermod -aG docker $USER && newgrp docker
```
Download the minikube binaries and install on the VM
```
~$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
~$ sudo install minikube-linux-amd64 /usr/local/bin/minikube
```
![get-minikube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1p9vao79m7134pat4zht.PNG)

Now, set docker as default driver for our kubernetes cluster setup
```
~$ minikube config set driver docker
```
![set-docker-to-minikube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/668yk2u8cdby5apy43tl.PNG)

Start Minikube, Check Kubernetes cluster status, & Remove
Let's start our Minikube cluster to kickstart our Kubernetes lab setup. (It will take few minutes, depend on your internet speed & supplied resources.)
```
~$ minikube start
```

![start-minikube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gm273r8q1u51jnl21jl.PNG)

We can verify the current running container components that constitute our Kubernetes cluster.
```
~$ minikube kubectl -- get pods -A
```


![get-pods-minikube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbd9y3ke1qcrp88skxbs.PNG)

![docker-ps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nt225u6464n5nd5sdhy0.PNG)

Now, we can use this lab setup to practice and test more about Kubernetes. When your tasks are over, we can stop the cluster and reprovision as needed.
```
~$ minikube stop
~$ minikube delete
```

![stop-minikube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y4b6k1thlw50zdpq95ot.PNG)

I hope these steps help you set up your own Kubernetes lab on your local machine to experiment and learn more. Thanks for reading.!