Context Switching Made Easy under Kubernetes powered Docker for Mac 18.02.0

Say Bye to Kubectx !

I have been a great fan of kubectx and kubectl which has been a fast way to switch between clusters and namespaces until I came across Docker for Mac 18.02. With the newer Docker for Mac 18.02 RC build, it is just a matter of a “toggle”. Life has become too easy to switch between dev, QA & production environment.

[Updated(2-Feb-2018) : Docker for Mac 18.02.0 CE RC2 build now comes with Kubernetes v1.9.2 for the first time. I upgraded my macOS High Sierra to RC2 build today and it just works flawlessly. Check it out]


New to Kubernetes Namespace Vs Context ?

Generally, software development teams partition their development pipelines into discrete units. These units take various forms in a discrete layout –

          Dev  >> Testing|QA >> Staging >> Production

The resulting layouts are ideally suited to Kubernetes Namespaces. Each environment or stage in the pipeline becomes a unique namespace.

In Kubernetes terminology, Namespaces are the way to partition a single Kubernetes cluster into multiple virtual clusters. Namespaces are a logical partitioning capability that enable one Kubernetes cluster to be used by multiple users, teams of users, or a single user with multiple applications without concern for undesired interaction. Each user, team of users, or application may exist within its Namespace, isolated from every other user of the cluster and operating as if it were the sole user of the cluster.

A major benefit of applying namespaces to the development cycle is that the naming of software components (e.g. micro-services/endpoints) can be maintained without collision across the different environments. This is due to the isolation of the Kubernetes namespaces. The fact that each namespace is logically discrete allows the development teams to work within an isolated “development” namespace.

Say, you have two clusters, one for development work and one for scratch work. In the development cluster, your frontend developers work in a namespace called frontend, and your storage developers work in a namespace called storage. In your scratch cluster, developers work in the default namespace, or they create auxiliary namespaces as they see fit. Access to the development cluster requires authentication by certificate. Access to the scratch cluster requires authentication by username and password.

Shown below is an example which clearly shows a file config-demo with this content:

apiVersion: v1
kind: Config
preferences: {}

- cluster:
  name: development
- cluster:
  name: scratch

- name: developer
- name: experimenter

- context:
  name: dev-frontend
- context:
  name: dev-storage
- context:
  name: exp-scratch

As shown above, a configuration file describes clusters, users, and contexts. Your config-demo file has the framework to describe two clusters, two users, and three contexts.

Under this blog post, I will showcase how to create 3 difference contexts – Google Cloud, Docker for Desktop & Minikube first and then how easy is it to toggle between them under Docker for Mac Platform. Let’s get started –


  • Docker For Mac 18.02 RC2 build


  • Enable Kubernetes under Preference Pane

Installing Minikube

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:
sysctl -a | grep machdep.cpu.features | grep VMX

Installing Minikube via brew

Ajeets-MacBook-Air:~ ajeetraina$ brew update && brew install kubectl && brew cask install minikube

Starting Minikube

Ajeets-MacBook-Air:~ ajeetraina$ minikube start
Starting local Kubernetes v1.9.0 cluster...
Starting VM...
Downloading Minikube ISO
 142.22 MB / 142.22 MB [============================================] 100.00% 0s
Getting VM IP address...
Moving files into cluster...
Downloading localkube binary
 162.41 MB / 162.41 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.

Viewing Kubernetes context selection pane

By now, you should see Minikube context appear

Verifying it using CLI

Ajeets-MacBook-Air:~ ajeetraina$ kubectl config get-contexts
CURRENT   NAME                          CLUSTER                      AUTHINFO             NAMESPACE
         docker-for-desktop            docker-for-desktop-cluster   docker-for-desktop
         gce                                                        cluster-admin
         kubernetes-admin@kubernetes   kubernetes                   kubernetes-admin
*         minikube                      minikube                     minikube

Viewing Minikube Dashboard

You can just type the below command to bring up qinikube dashboard in a sec.

minikube dashboard

Initializing Docker Swarm

Ajeets-MacBook-Air:testenviron ajeetraina$ docker swarm init
Swarm initialized: current node (zfxiqqjpjmwbvhm1ahjwio3s7) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-4vnxn6cbq4gtsjjvaluucncc8m71aexe11dhbm40aoxfqnr7s3-bevjmv2qpklluuhm6ufrfoas2

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Ajeets-MacBook-Air:testenviron ajeetraina$ docker node ls
ID                            HOSTNAME                STATUS              AVAILABILITY        MANAGER STATUS
zfxiqqjpjmwbvhm1ahjwio3s7 *   linuxkit-025000000001   Ready               Active              Leader
Ajeets-MacBook-Air:testenviron ajeetraina$ docker stack deploy -c docker-compose.yml myapp3
Creating network myapp3_default
Creating service myapp3_db1
Creating service myapp3_web1
Ajeets-MacBook-Air:testenviron ajeetraina$ docker stack ls
NAME                SERVICES
myapp3              2

Switching the context from Minikube to docker-for-desktop

Ajeets-MacBook-Air:testenviron ajeetraina$ kubectl config get-contexts
CURRENT   NAME                          CLUSTER                      AUTHINFO             NAMESPACE
          docker-for-desktop            docker-for-desktop-cluster   docker-for-desktop
          gce                                                        cluster-admin
          kubernetes-admin@kubernetes   kubernetes                   kubernetes-admin
*         minikube                      minikube                     minikube

Ajeets-MacBook-Air:testenviron ajeetraina$ kubectl config use-context docker-for-desktop
Switched to context "docker-for-desktop".

Verifying through Pane UI

Open up whale icon under D4M and see if the context switched successfully.

Enabling Kubernetes

Go to whale icon > Click on Preference > Click on Kubernetes > Enable Kubernetes > Show Systems Containers

It will take few minutes to get Kubernetes up and running. Expect it to take long time if you are enabling kubernetes for the first time based on your internet speed.

Clone the Repository

$git clone

Change to the right location

$cd docker101/play-with-kubernetes/examples/stack-deploy-on-mac/

Example-1 : Demonstrating a Simple Web Application

Building the Web Application Stack

$docker stack deploy -c docker-stack1.yml myapp1

Verifying the Stack

$docker stack ls

Verifying using Kubectl

$kubectl get pods

Verifying if the web application is accessible

$curl localhost:8083

Cleaning up the Stack

$docker stack rm myapp`

Example:2 – Demonstrating ReplicaSet

Building the Web Application Stack

$docker stack deploy -c docker-stack2.yml myapp2

Verifying the Stack

$docker stack ls

Verifying using Kubectl

$kubectl get pods
Ajeets-MacBook-Air:testenviron ajeetraina$ kubectl get stacks
myapp2    22m
Ajeets-MacBook-Air:testenviron ajeetraina$ kubectl get pods
NAME                    READY     STATUS    RESTARTS   AGE
db1-d977d5f48-l6v9d     1/1       Running   0          22m
db1-d977d5f48-mpd25     1/1       Running   0          22m
web1-6886bb478f-s7mvz   1/1       Running   0          22m
web1-6886bb478f-wh824   1/1       Running   0          22m

Adding Context for Google Cloud


  • Install google-cloud-sdk on macOS
  • Enable Google Cloud Engine API
  • Authenticate Your Google Cloud using gcloud auth

Creating GKE Cluster Node

Ajeets-MacBook-Air:~ ajeetraina$ gcloud container clusters create k8s-lab1 --disk-size 10 --zone asia-east1-a --machine-type n1-standard-2 --num-nodes 3 --scopes compute-rw
WARNING: The behavior of --scopes will change in a future gcloud release: service-control and service-management scopes will no longer be added to what is specified in --scopes. To use these scopes, add them explicitly to --scopes. To use the new behavior, set container/new_scopes_behavior property (gcloud config set container/new_scopes_behavior true).
WARNING: Starting in Kubernetes v1.10, new clusters will no longer get compute-rw and storage-ro scopes added to what is specified in --scopes (though the latter will remain included in the default --scopes). To use these scopes, add them explicitly to --scopes. To use the new behavior, set container/new_scopes_behavior property (gcloud config set container/new_scopes_behavior true).
Creating cluster k8s-lab1...done.
Created [].
To inspect the contents of your cluster, go to:
kubeconfig entry generated for k8s-lab1.
k8s-lab1  asia-east1-a  1.7.11-gke.1  n1-standard-2  1.7.11-gke.1  3          RUNNING

Verify it on Google Cloud


Master version	
1.7.11-gke.1 Upgrade available
Endpoint Show credentials
Client certificate	
Kubernetes alpha features	
Total size	
Master zone	

Connecting to Your GKE Cluster

You can connect to your cluster via command-line or using a dashboard too.

Ajeets-MacBook-Air:~ ajeetraina$ gcloud container clusters get-credentials k8s-lab1 --zone asia-east1-a --project spheric-temple-187614

Fetching cluster endpoint and auth data. kubeconfig entry generated for k8s-lab1.

Listing the Nodes

Ajeets-MacBook-Air:~ ajeetraina$ kubectl get nodes
NAME                                      STATUS    ROLES     AGE       VERSION
gke-k8s-lab1-default-pool-042d2598-591g   Ready     <none>    7m        v1.7.11-gke.1
gke-k8s-lab1-default-pool-042d2598-c633   Ready     <none>    7m        v1.7.11-gke.1
gke-k8s-lab1-default-pool-042d2598-q603   Ready     <none>    7m        v1.7.11-gke.1

Did you find this blog helpful?  Feel free to share your experience. Get in touch @ajeetsraina.

If you are looking out for contribution/discussion, join me at Docker Community Slack Channel.


2-minutes to Kubernetes Cluster on Docker for Mac 18.01 using Swarm CLI

Docker for Mac 18.01.0 CE is available for the general public. It holds experimental Kubernetes release running on Linux Kernel 4.9.75, Docker Compose 1.180 and Docker Machine 0.13.0. It is available only under Edge Release. Please note that this feature is still NOT available under Stable Release branch. This release brought a major fixes around insecure registry, VPNKit port,  DNS timeout issues and many more which you can refer under Release Notes section.

[Updated – 29/01/2018 – Docker Inc. introduced Kubernetes context selector UI in the recent Docker for Mac 18.02 RC1 release. If you have Minikube already running on the same system, you can switch the context in between Minikube & docker for Mac flawlessly. Refer this for more information]



In my previous blog, I talked about how to build Kubernetes Cluster in 3 minutes using Kubectl tool which comes by default with this release. But what if you are a die-hard fan of   Docker Swarm CLI like me, here is the good news – You can now use Swarm CLI to bring up Kubernetes Cluster. Under this post, I will show you how Swarm CLI can be used to bring up Kubernetes cluster in just 2 minutes.



  • Docker for Mac 18.01.0 CE Edge Release
  • Enable Kubernetes under Preference > Kubernetes Tab
  • Select Checkbox under Show System Container

A Quick 2-minutes ASCIINEMA video:

Here is 2-minutes video which shows how to get started from Zero to NGINX web server setup. It initiate with 0 pods, 0 external service and 0 deployments in Kubernetes terminology. Under this video, we will use the familiar docker stack CLI to bring up K8s cluster and then cleaning up in no seconds.

Liked the video? You can refer this link for detailed instructions and further examples.

As I dig deeper into Kubernetes architecture, below links might be useful for anyone who want to learn Kubernetes concepts in detail.

Getting Started with Kubernetes Concepts & Architecture

Building Kubernetes Dashboard on Docker for Mac in 1 min

Demystifying Kubernetes Namespace

Did you find this blog helpful?  Feel free to share your experience. Get in touch @ajeetsraina.

If you are looking out for contribution/discussion, join me at Docker Community Slack Channel.





Docker For Mac 1.13.0 brings support for macOS Sierra, now runs ARM & AARCH64 based Docker containers

Recently I purchased a brand new slim 13.3 inch Apple Mac Book  Air with an amazing 1.6GHz dual-core Intel Core i5 processor. Introducing Siri to newly re-branded macOS for the first time along with dozens of new features, it came by default running macOS 10.12.1 Sierra. macOS Sierra is the 13th major release of macOS(previously OS X)and successor of OS X El Capiton. ICYMI – Apple released macOS 10.12 Sierra open source Darwin code last November and can be accessed via . One of the first thing I wanted to try out was to see how easy is it to bring Docker 1.13.0 up and running on this system. Trust me, it was an amazing experience. Under this blog post, I am going to share my experience with Docker 1.13.0 and what you really need to know about Docker for Mac on macOS Sierra.


In case you are too new to Docker For Mac…

Last year during March time frame, Docker announced and released a native beta support for Mac and Windows, rightly termed as “Docker for Mac” & “Docker for Windows” respectively. They started with a closed beta & provided access to a couple of early adopters. During Dockercon 2016, they announced Final GA release for both the platforms.

Docker for Mac Vs. Docker Toolbox




  1. Docker for Mac only works on OS X 10.11 or newer macOS release.
  2. Apple Mac must be running 2010 or newer Mac system, with Intel HW support for MMU Virtualization.
  3. Docker for Mac require atleast 4GB of RAM to function smoothly.

Currently the installer comes in the form of 2 channels – stable and Beta. Under the stable channel, the installer is fully tested and comes with the latest GA version of Docker Engine. The Experimental feature is enabled by default.Under Beta channel, the installer provides the latest beta release of Docker for Mac with experimental features enabled by default.

Features enablement under Docker 1.13.0:


Getting Started with Docker Engine 1.13.0 on macOS Sierra

Installing Docker for Mac is one of fantastic experience I ever had installing any software. Just 3 simple steps:

  • Download Docker for Mac by clicking on this link and double-click Docker.dmg which opens up the installer.
  • Drag Moby the whale to the Application Folder as shown below:

Screen Shot 2017-01-29 at 2.52.53 PM


3.  Authorize with your system password and double-click to get started as shown below:

Screen Shot 2017-01-29 at 2.59.02 PM

Screen Shot 2017-01-29 at 2.59.12 PM

Screen Shot 2017-01-29 at 2.59.30 PM


Now this is really amazing. Docker for Mac comes with the default availability of docker-compose, docker-machine and experimental feature by default as shown below:

Screen Shot 2017-01-29 at 3.00.25 PM

  1. Verify the docker compose version:

bash-3.2# docker-compose version
docker-compose version 1.10.0, build 4bd6f1a
docker-py version: 2.0.1
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016

2. Verify the docker-machine version:

bash-3.2# docker-machine version

docker-machine version 0.9.0, build 15fd4c7

Kudos to Docker Engineers, the whale in the status bar is all you need to have a glimpse of overall Docker daemon running and easy way to configure Docker preferences & environment as per your need:

Screen Shot 2017-01-29 at 3.03.25 PM

Open the terminal and you can see that Docker for Mac runs on top of Alpine Linux v3.5, default storage driver as overlay2, Plugins support and many more.

Screen Shot 2017-01-29 at 6.04.50 PM

Multi-CPU Architecture Support(ARM, AARCH64 & PPC64le):

Apple Inc. added support for an ARM chip to the latest macOS Sierra 10.12 kernel. At the right time, Docker for Mac made binfmt_misc multi architecture support available,which means that now you can run containers for different Linux architectures, such as arm, aarch64 ppc64le and even s390x.

I couldn’t wait to test-drive few of Raspberry Pi ARM-based Docker images on my Mac Book Air. Here is how I tested few of ARM -based images:

bash-3.2# docker run -itd ajeetraina/centos7-arm /bin/bash

Unable to find image ‘ajeetraina/centos7-arm:latest’ locally

latest: Pulling from ajeetraina/centos7-arm

5584ea4c92c5: Pull complete

a3ed95caeb02: Pull complete

Digest: sha256:10989b1b7a3bdf826857ba5b3348956d495b9be1ced644a3aa7321cfbd705b04

Status: Downloaded newer image for ajeetraina/centos7-arm:latest


bash-3.2# docker ps

CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS               NAMES

a719fb80aac9        ajeetraina/centos7-arm   “/bin/bash”         2 minutes ago       Up 2 minutes                            suspicious_goldwasser

bash-3.2# docker exec -it a719f cat /etc/issue\S

Kernel \r on an \m


Please Note – The containers need to have the appropriate qemu binary inside the container to work, without qemu you can pull ARM-based Docker images but can’t run it.

Filesystem Sharing with OSXFS:

Docker for Mac brings a new shared filesystem, rightly called OSXFS  solution . OSXFS provides a close-to-native user experience for bind mounting OS X file system trees into Docker containers. It brings a number of unique capabilities as well as differences from a classical Linux file system. It does not use OSXFUSE and doesn’t run under, inside, or between OS X user space processes and the OS X kernel.

There are number of concerns around performance degradation around OSXFS and I think Docker team has rightly addressed it. It is worth reading to understand the problem statement and taking the right step. Said that, Docker team is continuously working to bring improvement under this space.

In the future blog post, I will talk about newer features and bug fixes which comes with Engine 1.13.0. Feel free to share if you like and reach out to me via @ajeetsraina(t).