# Launching a local Kubernetes lab using Minikube

> Learn to set up a local Kubernetes lab using Minikube for testing or development. Install, configure, and enable additional functionalities.

- Canonical: https://www.russ.cloud/2017/01/01/launching-a-local-kubernetes-lab-using-minikube/
- Published: 2017-01-01
- Author: Russ McKendrick
- Tags: Docker, Kubernetes

---

I have more and more people at work asking me about Docker and [Kubernetes](http://kubernetes.io/), 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](https://github.com/kubernetes/minikube).

> 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](https://docs.docker.com/) does, in fact it uses [libmachine](https://github.com/docker/machine/tree/master/libmachine) which is part of Docker Machine to launch the virtual machine.

I jumped straight into installing it. First of all, using [Homebrew](http://brew.sh/) and [Cask](https://github.com/Homebrew/homebrew-cask/) I installed the requirements which are;

- [kubectl](http://kubernetes.io/docs/user-guide/kubectl-overview/), this allows you control your Kubernetes cluster from the command line
- [virtualbox](http://virtualbox.org/), a way of running VMs on your local machine

I should point out that I did try using try using [docker-machine-driver-xhyve](https://github.com/zchee/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;

```bash frame="terminal" title="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;

```bash frame="terminal" title="Launching a local Kubernetes lab using Minikube 2/12"
brew cask install minikube
```


<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_1.png" alt="text" />

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

```bash frame="terminal" title="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.

<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_2.png" alt="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;

```bash frame="terminal" title="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
```


<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_3.png" alt="text" />

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

```bash frame="terminal" title="Launching a local Kubernetes lab using Minikube 5/12"
open $(minikube service my-nginx --url)
```


<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_4.png" alt="graphical user interface, text, application, email" />

To view the [Kubernetes Dashboard](http://kubernetes.io/docs/user-guide/ui/) I ran;

```bash frame="terminal" title="Launching a local Kubernetes lab using Minikube 6/12"
minikube dashboard
```


<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_5.png" alt="graphical user interface, text, chat or text message" />

Which opened my browser;

<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_6.png" alt="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;

```bash frame="terminal" title="Launching a local Kubernetes lab using Minikube 7/12"
eval $(minikube docker-env)
docker ps
```


<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_7.png" alt="graphical user interface, text" />

There are options to enable additional functionality, such as [Heapster](https://github.com/kubernetes/heapster). To install and enable Heapster I ran the following command;

```bash frame="terminal" title="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;

```bash frame="terminal" title="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;

```bash frame="terminal" title="Launching a local Kubernetes lab using Minikube 10/12"
minikube service list --namespace=kube-system
```


<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_8.png" alt="graphical user interface, text" />

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

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


<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_9.png" alt="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;

```bash frame="terminal" title="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 !!!

<Img src="/assets/2017-01-01-launching-a-local-kubernetes-lab-using-minikube/img/2017-01-01_launching-a-local-kubernetes-lab-using-minikube_10.png" alt="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;

- Github project, [https://github.com/kubernetes/minikube](https://github.com/kubernetes/minikube)
- Project Roadmap, [https://minikube.sigs.k8s.io/docs/contrib/roadmap/](https://minikube.sigs.k8s.io/docs/contrib/roadmap/)
