Getting Started With Kubernetes Is Easy With Minikube

4163

Getting started with any distributed system that has several components expected to run on different servers can be challenging. Often developers and system administrators want to be able to take a new system for a spin before diving straight into a full-fledged deployment on a cluster.

All in one installations are a good remedy to this challenge. They provide a quick way to test a new technology by getting a working setup on a local machine. They can be used by developers in their local workflow and by system administrators to learn the basics of the deployment setup and configuration of various components.

Typically, all-in-one installs are provided as a virtual machine. Vagrant has been a great tool for this. For example, OpenShift Origin provides an all-in-one VM, and OpenStack has DevStack.

To get started with Kubernetes easily, we now have an all-in-one solution: minikube.

Minikube will start a virtual machine locally and run the necessary Kubernetes components. The VM will get configured with Docker and Kubernetes via a single binary called localkube. The end result will be a local Kubernetes endpoint that you can use with the Kubernetes client kubectl.

This is very similar to Docker’s docker-machine with one main difference being that minikube only starts local virtual machines, it does not interact with public Cloud Providers.

Setup

For clarity, I will skip over the very few requirements (e.g., VirtualBox setup or another hypervisor) and go straight into “minikube” installation.

While you can build from source by grabbing it on GitHub, the easiest is to grab the released binary for your platform (packaging should come shortly). For example, on Linux:


```

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.8.0/minikube-linux-amd64

$ chmod +x minikube

$ sudo mv minikube /usr/local/bin/

```

With minikube now on your machine, you will be able to create a local Kubernetes endpoint. But if you are totally new to Kubernetes, you should also download the Kubernetes client kubectl. This client will interact with the Kubernetes API to manage your containers.

Get kubectl:


```

$ curl -Lo kubectl http://storage.googleapis.com/kubernetes-release/release/v1.3.0/bin/linux/amd64/kubectl

$ chmod +x kubectl

$ sudo mv kubectl /usr/local/bin/


```

You are now ready to use minikube. Just typing minikube at your shell prompt will return the usage. The first command to use, however, is the start command. This will boot the virtual machine that will run Kubernetes. Let’s do it:

```

$ minikube start

Starting local Kubernetes cluster...

Kubectl is now configured to use the cluster.

```

You can check the status of your minikube VM with the status command.

```

$ minikube status

Running

```

To see the kubectl is configured to talk to the minikube VM, try to list the nodes in your Kubernetes cluster. It should return a single node with the name minikubevm.

```

$ kubectl get nodes

NAME         STATUS    AGE

minikubevm   Ready     1h

```

And, to finish checking that everything is running, open your VirtualBox UI and see the minikube VM running.

Application Example

You are now all set with this all-in-one local Kubernetes install. You can use it to discover the API, explore the dashboard and start writing your first containerized applications that will easily migrate to a full Kubernetes cluster.

Explaining how an application is containerized and what are the various resources in Kubernetes is beyond the scope of this blog. But, to showcase minikube, we are going to create the canonical guestbook application. This application is made of a Redis cluster and a PHP front end. Containers are created via a Kubernetes resource called Deployments and exposed to each other via another Kubernetes primitive called a Service.

Let’s create the guestbook application on minikube. To do this, we will use the kubectl client and create all required resources by pointing at the YAML file that describes them in the examples folder of the Kubernetes source code.


```

$ kubectl create -f https://raw.githubusercontent.com/kubernetes/kubernetes/master/examples/guestbook/all-in-one/guestbook-all-in-one.yaml

service "redis-master" created

deployment "redis-master" created

service "redis-slave" created

deployment "redis-slave" created

service "frontend" created

deployment "frontend" created

```

The CLI tells you that it created three services and three deployments.

You can now open the Kubernetes dashboard automatically, and you will see all sorts of resources that have been created and that we will discuss in a later post.

```

$ minikube dashboard

```

Below is a snapshot of the Dashboard.

dashboard.png

To access the application front end, the quickest way in development setup like this one is to run a local proxy. This is due to the fact that a default Kubernetes service is not reachable outside the cluster.

```

$ kubectl proxy

```

The frontend service will now be accessible locally. Open it in your browser and enjoy the guestbook application.

```

$ open http://localhost:8001/api/v1/proxy/namespaces/default/services/frontend

```

Here is a snapshot of the guestbook application:

guestbook.png

Additional minikube commands

If you want to learn what is actually happening inside the minikube VM, you can SSH into it with the minikube ssh command.

Because Kubernetes uses the Docker engine to run the containers, you can also use minikube as a Docker host with the minikube docker-env command.

As a developer you might also be interested to test different versions of Kubernetes. Minikube allows you to do this. Check what versions are available to test with minikube get-k8s-versions and use the –kubernetes-version= flag in minikube start to set a specific version.

Finally, you can stop and delete the minikube VM with intuitive commands like minikube stop and minikube delete.

In conclusion, the minikube binary is by far the easiest and quickest way to get Kubernetes for a spin. It will allow you to learn the Kubernetes API, resource objects as well as how to interact with it with the kubectl client.

Read the next articles in this series: 

Rolling Updates and Rollbacks using Kubernetes Deployments

Helm: The Kubernetes Package Manager

Federating Your Kubernetes Clusters — The New Road to Hybrid Clouds

Enjoy Kubernetes with Python

Want to learn more about Kubernetes? Check out the new, online, self-paced Kubernetes Fundamentals course from The Linux Foundation. Sign Up Now!

Sebastien Goasguen (@sebgoa) is a long time open source contributor. Member of the Apache Software Foundation, member of the Kubernetes organization, he is also the author of the O’Reilly Docker cookbook. He recently founded skippbox, which offers solutions, services and training for Kubernetes.