Minikube for Learning Kubernetes Basics

What is Minikube?

Minikube is a lightweight implementation of Kubernetes. It allows you to create a single node Kubernetes cluster running on a Virtual machine on your local computer. It is very easy to install on any operating system and a great tool to get started with Kubernetes basics, without having to go through the hassle of installing a Kubernetes cluster from scratch.

Install Minikube

Make sure you have a virtual machine manager such as VirtualBox or a container manager such as Docker Desktop is installed on your machine as a prerequisite.

After that, installing Minikube is pretty straight forward. Just go to Minikube official website and download the executable or install through a package manager, depending on your OS.

Once the installation is finished, to verify the installation, run minikube version command in a command line.

Charith@Charith MINGW64 ~
$ minikube version
minikube version: v1.25.2
commit: 362d5fdc0a3dbee389b3d3f1034e8023e72bd3a7

You should see the minkube version in the output.

Start Minikube

Once Minikube is installed, you can start the Minikube cluster using minikube start command. This command will use the default VM driver on you machine, but sometimes it could fail. If that happens, you can explicitly specify a VM driver of your choice such as VirtualBox or Docker using the --vm-driver or --driver flag.

Some Useful Tips about Choosing a Driver

There could be certain limitations/complications depending on the driver you choose. At the time of writing this article, I came across following.

If you use the Docker driver…

  • You would find that it is much faster and takes significantly lesser time to start the cluster for the first time and in subsequent starts as well, compared to VirtualBox driver.
  • However, there are some additional steps you would have to follow when configuring a Load Balancer or Node Port type service (we would discuss about these services in later articles).
  • And the most significant drawback of all, at the time of writing this article, I found out that it is not possible to configure Ingress with Docker driver. I mean, you can configure it, but it won’t work the way you expect.

If you use the VirtualBox driver…

  • You would see some network failure issues from time to time, if you do not have enough memory and CPU resources allocated to the Minikube VM. Therefore, you need to make sure to provide those necessary parameters when starting the Minikube cluster for the first time.
  • Significantly slower to start than Docker, even with enough memory/CPU and SSD. Even some operations would take longer than Docker.
  • On the bright side, everything works as mentioned in the official documentation for the most part, which is a big reason to choose this driver.

If you decide to choose VirtualBox, provide the command as minikube start --driver=virtualbox --no-vtx-check --memory=8000m --cpus=4. This command will ensure there is enough memory and CPU for Minikube. If you do not explicitly specify these values, the default values would be 2GB memory and 2 CPUs, which I found was not enough.

If you decide to go with Docker, you can give the command as minikube start --vm-driver=docker. You would see the output as below in the command line.

$ minikube start --vm-driver=docker
* minikube v1.25.2 on Microsoft Windows 10 Home Single Language 10.0.19044 Build 19044
* minikube 1.26.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.26.0
* To disable this notice, run: 'minikube config set WantUpdateNotification false'

* Using the docker driver based on user configuration
* Starting control plane node minikube in cluster minikube
* Pulling base image ...
* Downloading Kubernetes v1.23.3 preload ...
    > gcr.io/k8s-minikube/kicbase: 379.06 MiB / 379.06 MiB  100.00% 511.72 KiB
* Creating docker container (CPUs=2, Memory=4000MB) ...
* Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
  - kubelet.housekeeping-interval=5m
  - Generating certificates and keys ...
  - Booting up control plane ...
  - Configuring RBAC rules ...
* 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

It would take a couple of minutes to download the relevant resources and start the cluster when doing it for the first time. The output would look as above when the installation is complete.

Run Kubectl Commands

Now that the Minikube cluster is running, we can try running some Kubectl commands. Kubectl is the CLI that we use to interact with any Kubernetes cluster.

Check Kubectl Version

To check the Kubectl version, you can run the kubectl version command.

Charith@Charith MINGW64 ~
$ kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.0", GitCommit:"4ce5a8954017644c5420bae81d72b09b735c21f0", GitTreeState:"clean", BuildDate:"2022-05-03T13:46:05Z", GoVersion:"go1.18.1", Compiler:"gc", Platform:"windows/amd64"}
Kustomize Version: v4.5.4
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.3", GitCommit:"816c97ab8cff8a1c72eccca1026f7820e93e0d25", GitTreeState:"clean", BuildDate:"2022-01-25T21:19:12Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"linux/amd64"}
Get Nodes

Run kubectl get nodes command to get the nodes in this cluster.

Charith@Charith MINGW64 ~
$ kubectl get nodes
NAME       STATUS   ROLES                  AGE    VERSION
minikube   Ready    control-plane,master   145m   v1.23.3
Get Cluster Info

Run kubectl cluster-info command to get cluster info.

Charith@Charith MINGW64 ~
$ kubectl cluster-info
Kubernetes control plane is running at https://127.0.0.1:52831
CoreDNS is running at https://127.0.0.1:52831/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Now that we have a Kubernetes cluster at our disposal, we can try more things with Kubernetes. In the next article, we will look into more Kubectl commands we can use to interact with our Kubernetes cluster.

Share this article if it was helpful!

Leave a Reply

Your email address will not be published. Required fields are marked *