If you ever used docker, You must have heard people raving about Kubernetes , but getting Kubernetes up and running locally was hard. Surely it was missing the great local development platform.
Minikube is the easiest way to run Kubernetes locally. It runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day.
Since Minikube runs locally instead of on a cloud provider, certain provider-specific features like LoadBalancers and PersistentVolumes will not work out-of-the-box. However, you can use NodePort, HostPath PersisentVolumes and several add-ons like DNS, dashboard, CNI, etc to test your apps locally before pushing to the production-grade cluster.
Installing Minikube is pretty easy since it’s available as a single binary. At the time of writing this article 0.17.1 is the latest version, to install –
Please visit this page for the latest release of Minikube .
In order to validate our deployment and check that everything went well, let’s start the local Kubernetes cluster:
Let’s start by first checking how many nodes are up:
You can checkout other awesome blogs regarding how to deploy your applications on newly created cluster.
Minikube is built on top of Docker’s libmachine and leverages the driver model to create, manage and interact with locally-run virtual machines.
Inspired by RedSpread’s localkube , Minikube spins up a single-process Kubernetes cluster inside a VM. Localkube bundles etc, DNS, the Kubelet and all the Kubernetes master components into a single Go binary and runs them all via separate go-routines.
Though community is working hard to make Minikube feature-rich, it has certain missing features like –
Helping Tips & Gotchas
Sharing docker daemon
Minikube contains a built-in Docker daemon for running containers. It is recommended to reuse the Docker daemon which Minikube uses for pure Docker use-cases as well. By using the same docker daemon as Minikube, you can speed up your local experiments. To share daemon in your shell:
Now when you do Docker builds, the images you build will be available to Minikube.
if you are on Mac, it’s better to use xhype hypervisor for speed and less memory usage.
Or set it permanently
Minikube aims to advance features via several addons , like ingress, registry credentials, DNS, dashboard, Heapster etc.
To enable an add-on, run –
You can also edit the addon’s config (YAML) file and apply against cluster to fulfill your use case.
Switching cluster version
Minikube have relatively unknown and very useful feature to switch cluster version to smoke test your app. To start Minikube with a cluster version –
Using private images
Minikube is that it won’t always have credentials to pull from private container registries. You should use ImagePullSecrets in PodSpec as defined on the official Image page.
When you are working locally, you may want to access cluster services using cli tools to quickly debug things. For example, you can expose redis using
Now you can simply use clients like ( `redis-cli` or `psql`, `mongo`) with the services running inside cluster. Forwarding a port with kubectl is fairly easy, however, it only works with single Pods and not with Services. Pretty neat.
Hot reloads via host mounts
it would be pretty neat if your code is reloaded when you change in editor, rather than building the image and deploying again. On OSX, All you have to do is create a host mount to mount your local directory into your container like :
Also, enable your web server to listen to file changes ( like `–reload` flag for gunicorn ). Unfortunately, host folder sharing is not implemented on Linux yet.
I hope this post helps people who are struggling setting up their own Kubernetes cluster and to get them quickly started. Here we got a single node Kubernetes cluster running locally, for purposes of learning, development, and testing, and will be using Minikube in next article to set up applications. Thanks for reading through this tutorial! Let me know if you found it useful in the comments 😉