I have more and more people at work asking me about Docker and Kubernetes , so I thought it would be good to write down some instructions on bringing up a small test lab on my laptop.

I had initially assumed that I would have to spend some time configuring a Vagrant box for this, but then I spotted the Minikube project .

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube 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.

Minikube launches a virtual machine and then can be used to manage the configuration much like the way Docker Machine does, in fact it uses libmachine which is part of Docker Machine to launch the virtual machine.

I jumped straight into installing it. First of all, using Homebrew and Cask I installed the requirements which are;

  • kubectl , this allows you control your Kubernetes cluster from the command line
  • virtualbox , a way of running VMs on your local machine

I should point out that I did try using try using docker-machine-driver-xhyve which is a libmachine driver that enables Docker Machine and libmachine powered applications to use xhyve which is the native macOS hypervisor, while it worked once it then failed to boot again.

Considering I will only be using Minikube to give people a quick overview I decided to stick with VirtualBox as it has worked without any problems.

To install these, I ran the following command;

Launching a local Kubernetes lab using Minikube 1/12
brew install kubectl
brew cask install virtualbox

Now the requirements are installed and configured it was time to install Minikube. To install Minikube, I ran the following;

Launching a local Kubernetes lab using Minikube 2/12
brew cask install minikube

text

Now that minikube was installed I ran the command below to launch my local Kubernetes cluster;

Launching a local Kubernetes lab using Minikube 3/12
minikube start

After a minute or two, it returned a message saying “Kubectl is now configured to use the cluster” and that was it, I had my local Kubernetes cluster up and running.

graphical user interface, text

To test it ran the following commands to launch two NGINX containers, check that everything is running and then bind the service to a port on the local Kubernetes cluster;

Launching a local Kubernetes lab using Minikube 4/12
kubectl run my-nginx --image=nginx --replicas=2 --port=80
kubectl get pods
kubectl expose deployment my-nginx --type=NodePort

text

Running the following command opened the exposed service in my browser;

Launching a local Kubernetes lab using Minikube 5/12
open $(minikube service my-nginx --url)

graphical user interface, text, application, email

To view the Kubernetes Dashboard I ran;

Launching a local Kubernetes lab using Minikube 6/12
minikube dashboard

graphical user interface, text, chat or text message

Which opened my browser;

graphical user interface, application

As minikube uses libmachine I can configure my local docker client to connect to the local Kubernetes cluster in the same way you would with a Docker Machine launched Docker host, I did this by running;

Launching a local Kubernetes lab using Minikube 7/12
eval $(minikube docker-env)
docker ps

graphical user interface, text

There are options to enable additional functionality, such as Heapster . To install and enable Heapster I ran the following command;

Launching a local Kubernetes lab using Minikube 8/12
minikube addons enable heapster

To check on the status of the service, I ran the following;

Launching a local Kubernetes lab using Minikube 9/12
kubectl get pods --namespace=kube-system

Once the Pod had a status of Running I checked the name of the service by running;

Launching a local Kubernetes lab using Minikube 10/12
minikube service list --namespace=kube-system

graphical user interface, text

Once I knew the name of the service I ran the command below to open the stats dashboard;

Launching a local Kubernetes lab using Minikube 11/12
open $(minikube service monitoring-grafana --namespace=kube-system  --url)

a screenshot of a computer

Once I had finished I had the option of either stopping or deleting the local Kubernetes cluster by running on of the following commands;

Launching a local Kubernetes lab using Minikube 12/12
minikube stop
minikube delete

As you may notice from the following terminal output there is no warning when deleting the cluster so make sure you do want to delete the local Kubernetes cluster !!!

graphical user interface, text

So, what are the drawbacks? Although I have spent the entire post referring to my “local Kubernetes cluster” it is only a single virtual machine, so I won’t be able to demonstrate the scheduler.

Also, as it is running locally, I won’t be able to show off any of the cloud-native load balancing integrations.

Other than that, there is more than enough for me to explain the basic concepts behine Kubernetes.

For more information on Minikube see the following;