Minikube on Mac OS X with VMware Fusion for local development - and a not so local future

docker
mac-os-x
kubernetes
vmware
Tags: #<Tag:0x00007f389ed7bf30> #<Tag:0x00007f389ed7bd78> #<Tag:0x00007f389ed7bbc0> #<Tag:0x00007f389ed7ba80>

#1

The simple way

This is a simple copy-paste guide to setup a Kubernetes test environment on Mac OS X with a package manager.

VMware Fusion

Installing VMware Fusion on Mac OS X is straight forward.

Here is something, that is relevant in context of this blog post. You should add the VMware CLI tools to your PATH, by adding a line like this to your .zshrc / .bashrc

# VMware Fusion command-line utils
export PATH=$PATH:"/Applications/VMware Fusion.app/Contents/Library"

If you follow this guide you should get to see this at some point:

➜  ~ vmrun list
Total running VMs: 1
/Users/me/.minikube/machines/minikube/minikube.vmx

Install kubectl

This is the first step. You will need this anyways, even if you simply get the Kubernetes hosts via GCP.

You can also install this via Homebrew:

==> Downloading https://homebrew.bintray.com/bottles/kubernetes-cli-1.10.0.high_sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/ef/ef0eae7ae4f6c157138fd53aa89c8ea5fecd8875809c406c7db21285140d5cc1?__gda__=exp=15230065
######################################################################## 100.0%
==> Pouring kubernetes-cli-1.10.0.high_sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/kubernetes-cli/1.10.0: 178 files, 52.8MB

Check.

➜  ~ which kubectl
/usr/local/bin/kubectl

minikube via Homebrew cask

➜  ~ brew install caskroom/cask/minikube
==> brew cask install caskroom/cask/minikube
==> Satisfying dependencies
All Formula dependencies satisfied.
==> Downloading https://storage.googleapis.com/minikube/releases/v0.25.2/minikube-darwin-amd64
######################################################################## 100.0%
==> Verifying checksum for Cask minikube
==> Installing Cask minikube
==> Linking Binary 'minikube-darwin-amd64' to '/usr/local/bin/minikube'.
🍺  minikube was successfully installed!

Get started with minikube and VMware Fusion

➜  ~ minikube --vm-driver=vmwarefusion --loglevel 2 start
Starting local Kubernetes v1.9.4 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Downloading localkube binary
 163.02 MB / 163.02 MB [============================================] 100.00% 0s
 0 B / 65 B [----------------------------------------------------------]   0.00%
 65 B / 65 B [======================================================] 100.00% 0sSetting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.

Ok, we live bois.

➜  ~ kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
deployment.apps "hello-minikube" created
➜  ~ kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed

Let’s enumerate the Pods:

➜  ~ kubectl get pod
NAME                            READY     STATUS    RESTARTS   AGE
hello-minikube-c6c6764d-jvfnt   1/1       Running   0          23s

And let’s send a GET request to the new service on port 8080.

➜  ~ curl $(minikube service hello-minikube --url)
CLIENT VALUES:
client_address=172.17.0.1
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://192.168.221.131:8080/

SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001

HEADERS RECEIVED:
accept=*/*
host=192.168.221.131:32492
user-agent=curl/7.54.0
BODY:
-no body in request-%

Works. Is this port public?

➜  ~ minikube service hello-minikube --url
http://192.168.221.131:32492
➜  ~ lsof -iTCP -sTCP:LISTEN
COMMAND   PID            USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
rapportd  512 me    3u  IPv4 0x683913b78a996ae7      0t0  TCP *:61655 (LISTEN)
rapportd  512 me    4u  IPv6 0x683913b79255153f      0t0  TCP *:61655 (LISTEN)

Hmh, so where is the socket?

➜  ~ vmrun list
Total running VMs: 1
/Users/me/.minikube/machines/minikube/minikube.vmx
➜  ~ vmrun listNetworkAdapters /Users/me/.minikube/machines/minikube/minikube.vmx
Total network adapters: 1
INDEX  TYPE         VMNET
0      nat          vmnet8

Ah, so the VMware guest is behind a NAT adapter. Any port mappings?

➜  ~ vmrun listPortForwardings vmnet8
Total port forwardings: 0

All good. So this Pod runs on a NATed VM, and it only available locally on the 192.168.0.0/24. It uses a 172.0.0.0/16 or something.

What processes run within the minikube VM?

➜  ~ minikube ssh
                         _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$ ps aux

Make use of minikube on Mac OS X with whalebrew and docker

Install Docker CE with Homebrew.

➜  ~ brew install docker
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (caskroom/cask).
No changes to formulae.

==> Downloading https://homebrew.bintray.com/bottles/docker-18.03.0.high_sierra.
==> Downloading from https://akamai.bintray.com/0f/0f8003a13c798733cff67a1916b4b
######################################################################## 100.0%
==> Pouring docker-18.03.0.high_sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/docker/18.03.0: 8 files, 50.3MB

Next: use minikube with the local docker tools.

➜  ~ eval $(minikube docker-env)
➜  ~ docker ps                  
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS               NAMES
27dd9bedff6a        k8s.gcr.io/echoserver                      "nginx -g 'daemon of…"   2 hours ago         Up 2 hours                              k8s_hello-minikube_hello-minikube-c6c6764d-jvfnt_default_241ed6bd-397d-11e8-893b-000c29b9a1c8_0
4db0cb03ab8b        gcr.io/google_containers/pause-amd64:3.0   "/pause"                 2 hours ago         Up 2 hours                              k8s_POD_hello-minikube-c6c6764d-jvfnt_default_241ed6bd-397d-11e8-893b-000c29b9a1c8_0

Now install whalebrew:

➜  ~ whalebrew install  whalebrew/pwgen
Unable to find image 'whalebrew/pwgen' locally

And:

➜  ~ file $(which pwgen)
/usr/local/bin/pwgen: a /usr/bin/env whalebrew script text executable, ASCII text

If the tool requires a local dotfile, you might need to change it.

With this setup you can aim create tools, which are simple to invoke and easily distributable.

E.g. these packages might be associated with some use-cases:

➜  ~ whalebrew search anaconda
...
continuumio/anaconda
continuumio/anaconda3
...
log2timeline/plaso

Lots of opportunities.

Summary

It’s possible to get started with Kubernetes with a few commands on Mac OS X. VMware Fusion has useful command-line utilities. whalebrew and minikube can be combined to some extend.