Spending Time with Docker and Kubernetes on macOS

Cloud native is the hype phrase of the day so spending time with Docker and Kubernetes on macOS is a good time investment. I’ve been working with Docker for at least 4 years. I originally stumbled across it during a planning session in Beerse, Belgium for a solution for HIV and TB medication management we were starting for countries in Africa. Since then, I have not had a chance to get my hands on Kubernetes. In this post I’ll take a look at the latest developments with Docker and Kubernetes on macOS.

About My Machine

I’ll be using my normal MacBook Pro with High Sierra (10.13.6) and 16GB of RAM as described here.

Cloud Native – A Quick Definition

Kubernetes ArchitectureI realize that this could be a generator of much commenting, but I’ll take a stab at what I mean by Cloud Native (CN) architectures. Solutions designed as “cloud native” use components/systems, deployment models, and management tools designed to maximize speed/efficiency/value when operating in virtualized environments (aka cloud providers). There are 3 basic elements: containers, orchestrators, and a more generalized segmentation of applications into microservices.

In this post I am going to take a look at two thirds of CN – the combination of Docker (the containers) and Kubernetes (K8s) (the orchestrator).

There’s a basic diagram showing all the bits and pieces involved in a Kubernetes cluster. The green box (master) basically controls the blue boxes (containers and the pods within them).

Two Choices for Kubernetes on macOS

One of the very nice things about Kubernetes is the quality of the documentation. The second is that things actually work as described. Quite an accomplishment for a complex set of components. All open-source too – which is really nice. Starting out at Kubernetes.io is an obvious good move. I’ve also found great content on lynda.com (https://www.lynda.com/Kubernetes-tutorials/Learning-Kubernetes/647663-2.html).  There’s great content on Wikipedia as well.

You can go thru all the work of installing a complete Kubernetes configuration on macOS. – this involves installing VirtualBox, kubectl, and miniKube or you can just install Docker and activate it’s Kubernetes support. That’s a lot simpler to get started, with the downside being that most tutorials and training materials are going to go with the former.

Just to torture myself, I’m going with the latter approach. If you do opt for the native approach, definitely consider using Homebrew to get stuff installed when possible.

The two approaches and what needs to get installed:Docker-Kubernetes

  • Native Kubernetes (VirtualBox, kubectl, and minikube, )
  • Docker Assisted (Docker with Kubernetes activated)

Docker on macOS is a binary installer and how to install it is very well documented on their site. Once installed, open up preferences and turn on Kubernetes. It will take ~60 seconds to get up and running. You can turn it on and off as needed.

Getting to Work with Kubernetes

Once it is up, you should be able to go to a terminal and get information on your cluster. Use commands like “kubectl version” to show version information or “kubectl get nodes” to list off the current set of nodes. The Docker K8s service is limited to 1 node and it should be labeled “docker-for-desktop”. There are a bunch of HelloWorld images you can grab and see if the basics are working:kubectl-docker

kubectl run hw --image=karthequian/helloworld --port=80
kubectl expose deployment hw --type=NodePort

The first command grabs an image, installs it, and starts it up. The second command then exposes this service to your machine so that you can load it up in a browser (in this example). This is pretty basic stuff for just messing around so not a production-ready example please. You can then use the command “kubectl get services” to get a list of what service are active and what port they are visible on. Pretty cool!

The Kubernetes Dashboard

What about a GUI dashboard? That’s a basic part of the native packages, but with the Docker version you need to do some extra things:

kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

then take a look at the nodes in the kube-system namespace:

kubectl get pods --namespace=kube-systemdashboard-pod

The dashboard should be listed there. It may take a few seconds to start up fully.

Then you can setup a simple proxy:

kubectl proxy

and now you should be able to load up the dashboard at http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default, select skip to get into the default dashboard (highly insecure!!).

That was kind of a brute force way to do that, but it seems that the default service type is ClusterIP, which cannot be exposed Kubernetes Dashboardoutside the cluster. There are some options:

  • For example, delete the service and explicitly declare it in the .yaml configuration file to be of type NodePort.
  • Create a new service specifying NodeType.

For now I’ll just use the proxy method above since I’m really just messing around on my laptop. When you get advanced enough you should probably think about going “native” to take advantage to the add-ons and in general the community information available to troubleshoot things.

Poking around today does show that to run this stuff in production systems requires lots of study. On that note – time to study this a bunch more…as I learn I’ll post more.Up next is to learn how to build my own images and deploy them into the cluster.

Its amazing what you can do when given a few hours to mess around. 🙂

Kubernetes Tutorials and Resources

Leave a Reply