Minikube - Developing and Testing locally with K8s

This post walks you through the first fundamental steps to get minikube up and running with homebrew.

Minikube - minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.


start minikube

$ brew install hyperkit
$ brew install minikube
$ minikube start --driver=hyperkit --memory 12000 --cpus 6
๐Ÿ˜„  minikube v1.24.0 on Darwin 12.0.1
โœจ  Using the hyperkit driver based on user configuration
๐ŸŒŸ  Enabled addons: storage-provisioner, default-storageclass
๐Ÿ„  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

hyperkit - HyperKit is a toolkit for embedding hypervisor capabilities in your application.

Private Registries

You can find all you need in the official documentation: Using a Private Registry

Itโ€™s a fancy mix of the minikube add-on registry and the Linux command socat - Multipurpose relay (SOcket CAT):

Note: Enabling and configuring the add-on is only required once.

$ minikube addons enable registry
    โ–ช Using image registry:2.7.1
    โ–ช Using image
๐Ÿ”Ž  Verifying registry addon...
๐ŸŒŸ  The 'registry' addon is enabled

Hint: You can list the addons with minikube addons list.

minikube addons configure registry-creds

Reconfigure the specs

Found this helpful hint about how to re-config a cluster here: Kubernetes Minikube Tutorial for Beginners

minikube stop
minikube config set memory 2500
minikube config set cpus 2
minikube start

๐Ÿ˜ No need to tear down the cluster if the initial sizing was wrong.

Changing the disk-size however required a restart. ๐Ÿค”

โ—  These changes will take effect upon a minikube delete and then a minikube start

The End

Finally delete the cluster with:

$ minikube delete --all --purge
๐Ÿ”ฅ  Deleting "minikube" in hyperkit ...
๐Ÿ’€  Removed all traces of the "minikube" cluster.
๐Ÿ”ฅ  Successfully deleted all profiles
๐Ÿ’€  Successfully purged minikube directory located at - [/Users/devop/.minikube]

Bonus - The Docker Environment

Giving this combo a try was inspired by Replacing Docker Desktop with hyperkit + minikube.

If you are a regular docker user you can continue using it piggybacked with your minikube installation. Switch on docker-env to "Configure environment to use minikubeโ€™s Docker daemon"

docker-env eval $(minikube docker-env)

eval $(minikube docker-env) 
docker run --rm -it --network=host alpine ash -c "apk add socat && socat TCP-LISTEN:5000,reuseaddr,fork TCP:$(minikube ip):5000"

Docker volumes

Docker commands using volume mounts like -v "$PWD":/workdir will not work out of the box due to minikube running in it's own environment.

Tip: Mount local working directory via minikube mount $(pwd)/workdir:/workdir

Docker ports

When running standard docker compose commands you might need an additional port forward to access your containers

ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip) -L '*:19088:' -N

Hint: The first port is on the host, the second the post exposed by the container inside minikube.

๐Ÿ™Œ Photo by Crissy Jarvis on Unsplash