Exploring Kubernetes on Docker for OS X
• Mark Eschbach
Kubernetes is a technology I have been interested in for a while. Recently I learned the OS X distribution of Docker includes Kubernetes using a solo master node. Sounds like a good place to start. First step is how do I do Kubernetes on OS X.
Hey look! Romin Irani published a medium article on the subject. Looks like he doing the dance in December of 2017. There is definitely a checkbox on the Kubernetes panel as of today but it looks like Experimental Features are also enabled. Now just waiting I guess…Perhaps I should have chosen to do this from home instead of a coffee shop :-).
Alrighty, that did not take too long. The kubectl
command is live! kubectl version
hangs though. Probably not
good. So it came back after a while with the client version and a timeout. Grr. Oh, it’s trying to connect to my
server at home. Derp.
Turns out the configuration is stored at ~/.kube/config
. I bet if I flip the ordering it will react different. Or,
better option, I use kubectl config use-context docker-for-desktop
. That worked as expected.
Annoyingly the article has an issue with double dashes being improperly converted to a single character. The upside is this forces me to type in the commands, or at least modify them. So maybe I’ll learn something. Port command works when fixing it for the right application. Later on they get fixed.
So the tutorial effectively go a cluster up and running with a single service using the following steps:
- Use the Docker utility on the menu bar to install Kubernetes into Docker for Mac
kubectl config use-context docker-for-desktop
to set the correct context if you operate on multiple systems.kubectl config view
to see what contexts are available.kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
to launch the Dashboard application.kubectl get pods --namespace=kube-system
to retrieve the name of the running Dashboard pod. It will look something likekubernetes-dashboard-7d5dcdb6d9-hcs2m
.kubectl port-forward kubernetes-dashboard-7d5dcdb6d9-hcs2m 8443:8443 --namespace=kube-system
to expose the dashboard on at https://localhost:8443 under your OS X instance.kubectl run hello-nginx --image=nginx --port=80
to run nginx. I believe the--port=80
exposes the port out of the pod, however I am not entirely certain.kubectl expose deployment hello-nginx --type=NodePort
exposes the HTTP service port on a random host port on your OS X instance. You may find the port by issuingkubectl describe service hello-nginx
and navigating to the port on your OS X instance.kubectl scale --replicas=3 deployment/hello-nginx
launches three instances of the Pod. According to the kubectl expose reference does not exactly clarify the difference between exposing a replicaset versus a deployment. Ah, so a deployment has one or more replicasets to control rolling out new versions of the application. They have solved a large number of failure cases and discuss in details what is happening there.kubectl delete deployment,services -l run=hello-nginx
will remove the nginx deployment and associated services from the system. Although not actually apart of the tutorial I feel like it is important to figure out how to return to a similar state as the start.