A Kubernetes cluster up and running (locally) in less than five minutes.

2017-10-23

Unless for the last year you’ve been living under a rock, you’d know about Kubernetes. In a nutshell Kubernetes is a sophisticated container scheduler and solid orchestrator for scalable infrastructures. To a beginner the whole Kubernetes ecosystem and terminology might appear overwhelming. However, whether you would like to give a go to Kubernetes, the team behind it has developed Minikube, a tool that makes it easy to run Kubernetes locally. In this instalment I’m going to walk you thought from setting up Minikube and run a Docker image on top of a Kubernetes cluster.

Requirements:

brew https://brew.sh

xhyve https://github.com/mist64/xhyve

or

virtualbox https://www.virtualbox.org/wiki/Downloads

Installation and setup:

xhyve hypervisor (preferred way)
brew install docker-machine-driver-xhyve xhyve

sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve

sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve

minikube config set vm-driver xhyve
Virtualbox hypervisor

Skip this whether you have Virtualbox already installed:

brew update && brew install caskroom/cask/virtualbox caskroom/cask/virtualbox-extension-pack
brew update && brew install kubectl caskroom/cask/minikube

minikube config set vm-driver virtualbox

Kubernetes cluster bootstrap:

Starting Kubernetes cluster:

minikube start

Expected output.

Starting local Kubernetes v1.7.5 cluster...
Starting VM...
Downloading Minikube ISO
 139.09 MB / 139.09 MB [============================================] 100.00% 0s
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.

Cluster status check:

minikube status

Expected output.

minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100

Creating a flaskapp deployment.

This will schedule our application into the cluster node.

kubectl run flaskapp  --image=p0bailey/docker-flask:latest

kubectl get deployment

Expected output.

NAME       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
flaskapp   1         1         1            1           1m

Get Kubernetes pods information:

kubectl get pod

Expected output.

NAME                        READY     STATUS    RESTARTS   AGE
flaskapp-2458185843-r70w1   1/1       Running   0          2m

Operating the cluster:

Exposing flaskapp using a load balancer service:

kubectl expose deployment flaskapp --type=LoadBalancer --port=80

Accessing the flask application.

minikube service flaskapp --url

Once the url gets generated, point your browser to it and enjoy your first Kubernetes setup.

Kubernetes internals:

To view the the kubernetes dashboard URL for your local cluster:

minikube dashboard