Getting to know Minikube

This post is part of the series Prepare and Deploy python app to Kubernetes

👈 Previous post: Containerizing python flask application

At the end of this series, we will have a fully working flask app in Kubernetes. The app itself that we are using, can be found here: https://github.com/brnck/k8s-python-demo-app

Minikube is a local Kubernetes, focusing on making it easy to learn and develop for Kubernetes. In this guide, we are not going to deploy anything to Minikube yet. We are just going to get familiar with the tool itself

Install Minikube by using one of the provided procedure in the official documentation here

Initial start

Make sure the docker daemon is running on your machine. When starting Minikube for the first time, give it some time to download all the dependencies.

minikube start
😄 minikube v1.19.0 on Darwin 11.2.3
✨ Automatically selected the docker driver. Other choices: hyperkit, virtualbox, ssh
<...>
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

And there it is. You have Kubernetes up and running in your own machine.

Right now you have started Kubernetes using docker as a driver. However, I always prefer using VirtualBox as a driver over a docker. Basically what it does is that Minikube spins up a new virtual machine on your machine and provisions Kubernetes cluster in it. If you want to be on the same side as me, you can reprovision cluster on VirtualBox as well

Recreating the cluster

Let’s destroy the previously created cluster:

minikube delete
🔥 Deleting "minikube" in docker ...
<...>
💀 Removed all traces of the "minikube" cluster.

Create a new one. It’ll take a while as well since it needs to download VirtualBox box:

minikube start --driver=virtualbox
😄 minikube v1.19.0 on Darwin 11.2.3
✨ Using the virtualbox driver based on user configuration
<...>
👍 Starting control plane node minikube in cluster minikube
🔥 Creating virtualbox VM (CPUs=2, Memory=4000MB, Disk=20000MB) ...
<...>
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Basic commands

Check status

minikube status                   
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

Stop the cluster

Stop command stops the cluster, but it does not destroy it completely. This is very useful when you’re switching from some tasks related to Minikube and you want to free up the resources that it took.

minikube stop       
✋ Stopping node "minikube" ...
🛑 1 nodes stopped.

Let’s check the status after the stop:

minikube status
minikube
type: Control Plane
host: Stopped
kubelet: Stopped
apiserver: Stopped
kubeconfig: Stopped

Let’s start the cluster again:

minikube start
😄 minikube v1.19.0 on Darwin 11.2.3
✨ Using the virtualbox driver based on existing profile
👍 Starting control plane node minikube in cluster minikube
🔄 Restarting existing virtualbox VM for "minikube" ...
🐳 Preparing Kubernetes v1.20.2 on Docker 20.10.4 ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

When starting stopped cluster, flags like — driver, — memory, and so on are not needed anymore. Initial flags are only needed when you create a cluster from scratch

Delete the cluster

Usually, it’s good to destroy the cluster once in a while. Also, you might need a bigger cluster with more CPU or RAM or a different k8s version. That’s when delete command kicks in. It completely destroys VM (and k8s cluster with it) so you could recreate the cluster from scratch

minikube delete
🔥 Deleting "minikube" in virtualbox ...
💀 Removed all traces of the "minikube" cluster.

Advanced commands

Let’s say we need a cluster with more resources or we need to reach it through ingress controller or we want to see a nice dashboard that Kubernetes provide or we even want a different k8s cluster version. It’s all possible with just extra flags or additional commands

Provision cluster with additional resources

As you have probably noticed above, Minikube by default provision VM with CPUs=2, Memory=4000MB, Disk=20000MB. We can tweak resources on the initial minikube start. Also, let’s run older k8s version

minikube start --driver=virtualbox --cpus=3 --memory=6g --disk-size=40g --kubernetes-version=1.19.0
😄 minikube v1.19.0 on Darwin 11.2.3
✨ Using the virtualbox driver based on user configuration
👍 Starting control plane node minikube in cluster minikube
🔥 Creating virtualbox VM (CPUs=3, Memory=6144MB, Disk=40000MB) ...
<...>

❗ /usr/local/bin/kubectl is version 1.21.0, which may have incompatibilites with Kubernetes 1.19.0.
▪ Want kubectl v1.19.0? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

And that’s it. You now have a cluster with increased resources

Addons list

Addons are like extra functionality which can be deployed with only one command. Usually, you would need to configure them manually, but luckily Minikube does that for you

Let’s check available addons:

minikube addons list                                                               
|-----------------------------|----------|--------------|
| ADDON NAME | PROFILE | STATUS |
|-----------------------------|----------|--------------|
| ambassador | minikube | disabled |
| auto-pause | minikube | disabled |
| csi-hostpath-driver | minikube | disabled |
| dashboard | minikube | disabled |
| default-storageclass | minikube | enabled ✅ |
| efk | minikube | disabled |
| freshpod | minikube | disabled |
| gcp-auth | minikube | disabled |
| gvisor | minikube | disabled |
| helm-tiller | minikube | disabled |
| ingress | minikube | disabled |
| ingress-dns | minikube | disabled |
| istio | minikube | disabled |
| istio-provisioner | minikube | disabled |
| kubevirt | minikube | disabled |
| logviewer | minikube | disabled |
| metallb | minikube | disabled |
| metrics-server | minikube | disabled |
| nvidia-driver-installer | minikube | disabled |
| nvidia-gpu-device-plugin | minikube | disabled |
| olm | minikube | disabled |
| pod-security-policy | minikube | disabled |
| registry | minikube | disabled |
| registry-aliases | minikube | disabled |
| registry-creds | minikube | disabled |
| storage-provisioner | minikube | enabled ✅ |
| storage-provisioner-gluster | minikube | disabled |
| volumesnapshots | minikube | disabled |
|-----------------------------|----------|--------------|

The most used addons that you are probably going to deal with will be metrics-server (to check pods resources consumption) and ingress (to be able to simulate ingress traffic from outside the cluster)

Enable addons

Let’s enable metrics-server:

minikube addons enable metrics-server
▪ Using image k8s.gcr.io/metrics-server/metrics-server:v0.4.2
🌟 The 'metrics-server' addon is enabled

Let’s enable ingress:

minikube addons enable ingress       
▪ Using image k8s.gcr.io/ingress-nginx/controller:v0.44.0
▪ Using image docker.io/jettech/kube-webhook-certgen:v1.5.1
▪ Using image docker.io/jettech/kube-webhook-certgen:v1.5.1
🔎 Verifying ingress addon...
🌟 The 'ingress' addon is enabled

Let’s check addons again:

minikube addons list                 
|-----------------------------|----------|--------------|
| ADDON NAME | PROFILE | STATUS |
|-----------------------------|----------|--------------|
| ambassador | minikube | disabled |
| auto-pause | minikube | disabled |
| csi-hostpath-driver | minikube | disabled |
| dashboard | minikube | disabled |
| default-storageclass | minikube | enabled ✅ |
| efk | minikube | disabled |
| freshpod | minikube | disabled |
| gcp-auth | minikube | disabled |
| gvisor | minikube | disabled |
| helm-tiller | minikube | disabled |
| ingress | minikube | enabled ✅ |
| ingress-dns | minikube | disabled |
| istio | minikube | disabled |
| istio-provisioner | minikube | disabled |
| kubevirt | minikube | disabled |
| logviewer | minikube | disabled |
| metallb | minikube | disabled |
| metrics-server | minikube | enabled ✅ |
| nvidia-driver-installer | minikube | disabled |
| nvidia-gpu-device-plugin | minikube | disabled |
| olm | minikube | disabled |
| pod-security-policy | minikube | disabled |
| registry | minikube | disabled |
| registry-aliases | minikube | disabled |
| registry-creds | minikube | disabled |
| storage-provisioner | minikube | enabled ✅ |
| storage-provisioner-gluster | minikube | disabled |
| volumesnapshots | minikube | disabled |
|-----------------------------|----------|--------------|

Kubernetes dashboard

K8s has a very nice dashboard that can provide useful information without consuming its CLI tool kubectl. To enable it, execute this command:

minikube dashboard  
🔌 Enabling dashboard ...
▪ Using image kubernetesui/dashboard:v2.1.0
▪ Using image kubernetesui/metrics-scraper:v1.0.4
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:53197/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

It will open a web page in your browser:

Kubernetes dashboard

The dashboard will be accessible until the command will be stopped.

Conclusion

We have covered the basic usage of Minikube. If you want, you can spend more time with it by trying to interact with the cluster using kubectl and deploy applications. Otherwise, let’s proceed to the next guide where we are going to write Kubernetes manifests for the application and deploy it to the Minikube cluster.

DevOps