search by tags

for the user

adventures into the land of the command line

setting up minikube on mac osx


Requirements (one of):

kvm (driver installation)
xhyve (driver installation)

Install kubectl:

$ curl -LO`curl -s`/bin/darwin/amd64/kubectl
$ chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin/kubectl

-- OR --

$ brew install kubectl

Install docker for mac.

Then install minikube:

$ brew cask install minikube
==> Tapping caskroom/cask
Cloning into '/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask'...
  minikube was successfully installed!

Start minikube:

$ minikube start
Starting local Kubernetes v1.8.0 cluster...
Starting VM...
Downloading Minikube ISO
 140.01 MB / 140.01 MB [============================================] 100.00% 0s
Getting VM IP address...
Moving files into cluster...
Downloading localkube binary
 148.56 MB / 148.56 MB [============================================] 100.00% 0s
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.

Load the kubernetes dashboard:

$ minikube dashboard

This will launch your browser into it at!/overview?namespace=default


You can also use the kubectl binary to interact with the minikube cluster:

$ kubectl get nodes
minikube   Ready     none      3m        v1.8.0

Create a deployment

$ kubectl run nginx --image=nginx --port=80
deployment "nginx" created

Create a service

$ kubectl expose deployment nginx --type=NodePort
service "nginx" exposed

Open a service

$ minikube service nginx
Waiting, endpoint for service is not ready yet...
Opening kubernetes service default/nginx in default browser...

The above 3 steps deployed a boring nginx container. 


To point the docker client towards minikube’s docker environment, run the command below.

$ eval $(minikube docker-env)

Now, when you build a docker image, the Kubernetes cluster is able to use it directly.

$ docker ps -a
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS               NAMES
30b77dd46fc9        nginx                                                 "nginx -g 'daemon ..."   14 minutes ago      Up 14 minutes                           k8s_nginx_nginx-7cbc4b4d9c-z8jjr_default_35d23654-d512-11e7-ad9e-08002772ac06_0
7c237662af09              "/pause"                 14 minutes ago      Up 14 minutes                           k8s_POD_nginx-7cbc4b4d9c-z8jjr_default_35d23654-d512-11e7-ad9e-08002772ac06_0
84bd1b443c62   "/dashboard --inse..."   18 minutes ago      Up 18 minutes                           k8s_kubernetes-dashboard_kubernetes-dashboard-pxl2k_kube-system_b5bcd675-d511-11e7-ad9e-08002772ac06_0
693095819a5b        fed89e8b4248                                          "/sidecar --v=2 --..."   18 minutes ago      Up 18 minutes                           k8s_sidecar_kube-dns-6fc954457d-nn2sz_kube-system_b5e6fe42-d511-11e7-ad9e-08002772ac06_0
2cba69aaa531        459944ce8cc4                                          "/dnsmasq-nanny -v..."   18 minutes ago      Up 18 minutes                           k8s_dnsmasq_kube-dns-6fc954457d-nn2sz_kube-system_b5e6fe42-d511-11e7-ad9e-08002772ac06_0
f51eba8a5bda        512cd7425a73                                          "/kube-dns --domai..."   18 minutes ago      Up 18 minutes                           k8s_kubedns_kube-dns-6fc954457d-nn2sz_kube-system_b5e6fe42-d511-11e7-ad9e-08002772ac06_0
dd4a8dbdfb16              "/pause"                 18 minutes ago      Up 18 minutes                           k8s_POD_kube-dns-6fc954457d-nn2sz_kube-system_b5e6fe42-d511-11e7-ad9e-08002772ac06_0
377cb96112ef              "/pause"                 18 minutes ago      Up 18 minutes                           k8s_POD_kubernetes-dashboard-pxl2k_kube-system_b5bcd675-d511-11e7-ad9e-08002772ac06_0
70294947fd35        0a951668696f                                          "/opt/"    18 minutes ago      Up 18 minutes                           k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_9831e93c3188555873fdb49f43198eef_0
c646c86e3feb              "/pause"                 18 minutes ago      Up 18 minutes                           k8s_POD_kube-addon-manager-minikube_kube-system_9831e93c3188555873fdb49f43198eef_0

Some examples

This one builds an image from a Dockerfile which is a web server, serving an index.html

$ docker image ls
REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE
flow-1                                                 1                   0b7d74b5b00e        1 second ago        15.5MB
nginx                                                  latest              9e7424e5dbae        6 days ago          108MB
nginx                                                  stable-alpine       72a20a008f56        3 weeks ago         15.5MB         1.14.5              fed89e8b4248        2 months ago        41.8MB        1.14.5              512cd7425a73        2 months ago        49.4MB   1.14.5              459944ce8cc4        2 months ago        41.4MB    v1.7.0              284ec2f8ed6c        2 months ago        128MB    v1.6.3              691a82db1ecd        4 months ago        139MB            v6.4-beta.2         0a951668696f        5 months ago        79.2MB                   3.0                 99e59f495ffa        19 months ago       747kB

Deploy and run the new image with kubernetes:

$ kubectl run flow-1 --image=flow-1:1 --port=80
deployment "flow-1" created
$ kubectl expose deployment flow-1 --type=NodePort
service "flow-1" exposed
$ minikube service flow-1
Opening kubernetes service default/flow-1 in default browser...

The browser will open up a new page, but you will see a blank page, because the blog’s example has been moved to and so the image reference in this git repo is broken. Also you can see the container deployed:

$ kubectl get pod
NAME                      READY     STATUS    RESTARTS   AGE
flow-1-568c7d77c4-nwbc9   1/1       Running   0          25s
nginx-7cbc4b4d9c-z8jjr    1/1       Running   0          51m

Make some changes: change the images in the index.html to something else and iterate

$ make local
Sending build context to Docker daemon  9.216kB
Step 1/4 : FROM nginx:stable-alpine
 ---> 72a20a008f56
Step 2/4 : COPY config/nginx.conf /etc/nginx/nginx.conf
 ---> Using cache
 ---> 586ef15f6d97
Step 3/4 : COPY config/default.conf /etc/nginx/conf.d/default.conf
 ---> Using cache
 ---> 700d8eaa280a
Step 4/4 : COPY website /usr/share/nginx/html/
 ---> cb37a5d53789
Removing intermediate container 9da09af64538
Successfully built cb37a5d53789
Successfully tagged flow-1:tmp-1511967704
kubectl set image deployment flow-1 *=flow-1:tmp-1511967704
deployment "flow-1" image updated

Reload the browser and the page is updated with your new images, nice!


Let’s clean up and remove the deployment and service we just created.

$ kubectl delete deploy,svc flow-1
deployment "flow-1" deleted
service "flow-1" deleted

To pack up and go home:

$ minikube stop
Stopping local Kubernetes cluster...
Machine stopped.