The Docker team announced support for running Kubernetes using the Docker for Mac application. For a while, it was only available on unstable Edge releases of the Mac application.
Docker for Mac’s Kubernetes cluster is now available in the stable release channel! 🎉
This makes running Kubernetes for local development so much easier. You no longer need to install and run a separate cluster using something like Minikube. (Though, if you need to, I have a guide on installing Minikube on your Mac.)
It's available on Docker Community Edition version 18.06.0-ce-mac70 2018-07-25
or later.
Setting up kubectl to use Docker for Mac is simple.
If you don't already have kubectl installed, the easiest way is with Homebrew.
brew install kubernetes-cli
docker-for-desktop
. This will switch kubectl to the docker-for-desktop
context.kubectl config current-context
in a Terminal window. It should output docker-for-desktop
if kubectl’s context has updated.kubectl config view
to output
all your available kubectl contexts. (I have a chapter in my book that explains kubectl config in detail)# ~ âź© kubectl config view | |
apiVersion: v1 | |
clusters: | |
- cluster: | |
insecure-skip-tls-verify: true | |
server: https://localhost:6443 | |
name: docker-for-desktop-cluster | |
- cluster: | |
certificate-authority: /Users/matthewpalmer/.minikube/ca.crt | |
server: https://192.168.99.100:8443 | |
name: minikube | |
contexts: | |
- context: | |
cluster: docker-for-desktop-cluster | |
user: docker-for-desktop | |
name: docker-for-desktop | |
- context: | |
cluster: minikube | |
user: minikube | |
name: minikube | |
current-context: docker-for-desktop | |
kind: Config | |
preferences: {} | |
users: | |
- name: docker-for-desktop | |
user: | |
client-certificate-data: REDACTED | |
client-key-data: REDACTED | |
- name: minikube | |
user: | |
client-certificate: /Users/matthewpalmer/.minikube/client.crt | |
client-key: /Users/matthewpalmer/.minikube/client.key |
Once you’ve set up kubectl to use Docker for Mac’s Kubernetes cluster, you can run your first pod!
Create a file called pod.yaml
containing the following YAML configuration.
kind: Pod | |
apiVersion: v1 | |
metadata: | |
name: example-pod | |
spec: | |
containers: | |
- image: nginx | |
name: example-container |
Now run the pod, and then check its status as it gets run on Docker for Mac’s single node cluster
$ kubectl create -f pod.yaml pod "example-pod" created $ kubectl get pods NAME READY STATUS RESTARTS AGE example-pod 1/1 Running 0 2m
I’d expect Minikube to stick around for a while—it’s a much more stable and mature implementation of a single-node Kubernetes cluster that you can run locally on your Mac. But Docker for Mac is a great, simple way to run a simple cluster on your local machine. Plus, the Docker menu bar icon gives you a new, fast way to switch kubectl contexts.