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:
- Download the installer here https://github.com/kubernetes/minikube/releases/latest/download/minikube-installer.exe and run through the installer.
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:
- Download the binary at https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64
- Put the binary somewhere in your path, rename it to
minikube
and make it executable. See https://kubernetes.io/docs/tasks/tools/install-minikube/#install-minikube-via-direct-download if you get stuck on this step.
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:
[email protected]:/# 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:
- CF Operator’s Perspective on Starting K8s – Part 1 – If you already are a Cloud Foundry operator I review concepts you already know from that platform and how to translate these to Kubernetes on Minikube.
- CF Operator’s Perspective on Starting K8s – Part 2 – The follow up to the riveting Part 1 post, I crack open the etcd database in Kubernetes to show how it is used. The same etcd database is also in the Minikube Kubernetes cluster.
- Running the CrunchyData Postgres Operator on Minikube – Operators are an advanced way of provisioning services like PostgreSQL on Kubernetes, specifically an operator from CrunchyData. This blog discovers how to get this operator functioning happily on Minikube.
- Modifying the PostgreSQL Helm Chart to Emit Logging – Three methods to enable the PostgreSQL Helm Chart to emit all SQL queries into the logs so they can be consumed by pgBadger. To make this work on Minikube the service type is changed to
NodePort
- Adding pgBadger to the PostgreSQL Helm Chart – Overview of four methods of adding a pgBadger container read logs from an instance of a PostgreSQL Helm Chart. Without changing the chart!
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!