Stark & Wayne

The Tool to Start Your Journey with Kubernetes: Minikube

Photo by Braden Collum on Unsplash

Minikube is a nifty tool to start playing with Kubernetes without incurring any additional costs since you run it on your own laptop.  It runs as a virtual machine locally on VirtualBox or VMware Fusion and installs the kubectl CLI which you'll need to interact with the clusters.  The best part is you can run as many Kubernetes clusters as you like until your laptop levitates from the cooling fans!

Prerequisites

You'll need to have either VirtualBox (free) or VMware Fusion (not free) installed.  Since VirtualBox is more budget friendly you can install VirtualBox by:

Installing Minikube

On Windows:

On your Mac:

Install Homebrew if you haven't already by:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Now use homebrew to install minikube

brew install minikube

On Linux:

Start Your First Cluster

This is as easy as:

minikube start

To push your very first kubernetes pod (an instance of PostgreSQL) run:

kubectl run pg1 --image=postgres:11.2

Show the list of pods running via kubectl get pods and get an output similar to:

➜  ~ git:(master) ✗ kubectl get pods
NAME                  READY   STATUS              RESTARTS   AGE
pg1-dd7f88548-k2drf   0/1     ContainerCreating   0          7s

To connect to the pod run kubectl exec -it <pod name> -- bash:

# From the example above with the pod name pg1-dd7f88548-k2drf
kubectl exec -it pg1-dd7f88548-k2drf  -- bash

Once connected to the pod you can connect to Postgres via the psql command:

root@pg1-dd7f88548-k2drf:/# psql -U postgres -p 5432 postgres
psql (11.2 (Debian 11.2-1.pgdg90+1))
Type "help" for help.

postgres=#

Now you are connected to an instance of PostgreSQL running on Kubernetes!

Start Your Second Cluster

Want a second cluster?  Simply supply the name of the second cluster when you start minikube:

minikube start -p my_other_cluster

This new cluster will automatically be targeted with the kubectl CLI.

Using Minikube

I have a number of blog posts on customizing various tools to specifically use Minikube's version of Kubernetes.  Here is a quick overview of them:

Turn off the Laptop Hover Function

To stop the default cluster run:

minikube stop

To stop any additional clusters you created:

minikube stop -p my_other_cluster

In a few moments your fans will drop to a lower speed, be sure to have a safe landing spot for your laptop!

Final Thoughts

In all seriousness, a single cluster on my laptop held a surprising number of helm chart instances, stateful sets, pods, etc... until it finally stopped scheduling new pods.  If you run into a situation where pods stop getting scheduled simply remove some of the deployments (or a few dozen helm charts) you aren't using anymore.

Minikube is a great way to get started with a local running Kubernetes cluster.  As you get closer to how do I run this in production you'll look towards Managed Kubernetes clusters from the likes of AWS, Azure, GCP or you can make your own with tools like kubeadm or CFCR.

Enjoy!