Sign in

Open in app

Get started

Tweaking Docker Desktop’s Kubernetes on Win/Mac

Chris
Follow

Sep 23, 2019 · 5 min read

Docker Desktop makes it easy to run a single-node Kubernetes cluster on Windows and macOS. Here are four essential tweaks for it.

Kubernetes can get activated in the Docker Desktop settings

Docker Desktop for Mac and Windows allows to install and start a single-node Kubernetes (k8s) cluster in one click for easy local testing and development.

The result of enabling Kubernetes in the Docker Desktop preferences is a rather minimal k8s cluster — and it might make sense to install and enable some additional components before starting to hack with kubectl .

1. install the helm package manager

Helm is a package manager for k8s. It allows to define and install applications for k8s. Packages are called helm charts. They are currently the de-facto standard for installing apps and extensions on k8s clusters. (For example, installing grafana with helm looks like: helm install --name my-grafana stable/grafana ).

helm consists of a client (helm) and a cluster side component (tiller), that can get installed through the client. The client is a single binary file.

To install helm:

download the helm client from the github releases page and place it in a PATH location (i.e. /usr/local/bin or c:\windows\system32)

install tiller on the k8s cluster by running:

$ helm init --history-max 200
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.

To verify that everything is working, we can now install and delete an example chart:

Let’s use the grafana app as an example. First, we install the grafana chart:

$ helm repo update
$ helm install --name my-grafana stable/grafana

Now let’s start to forward grafana’s http port to localhost so that we can access its webinterface:

$ export POD_NAME=$(kubectl get pods --namespace default -l "app=grafana,release=my-grafana" -o jsonpath="{.items[0].metadata.name}")$ kubectl --namespace default port-forward $POD_NAME 3000 &

Now we should be able to access the grafana webinterface from http://localhost:3000

the Grafana webinterface

OK, that worked. Helm is ready. Now we can delete the installed test app.

$ helm delete --name my-grafana
release "my-grafana" deleted

2. macOS only: enable shell auto-completion for kubectl

kubectl supports auto-completion for bash. When enabled, kubectl commands can get auto-completed by pressing [TAB] and all possible options are shown by double-[TAB]’ing.

To enable bash completion for kubectl, we can run:

$ kubectl completion bash > /usr/local/etc/bash_completion.d/kubectl

In a new Terminal session we should now be able to use kubectl with auto-completion.

3. fix “kubectl top”

kubectl top pods and kubectl top nodes are useful commands to show CPU and memory utilisation of running pods or nodes in the cluster.

Unfortunately on a Docker Desktop Kubernetes installation it isn’t working out of the box:

$ kubectl top pods --all-namespaces
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)$ kubectl top nodes
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)

Due to the rather minimal nature of Docker Desktop’s Kubernetes distribution the k8s metrics-server component is “missing”. (For the same reason horizontal pod autoscaling doesn’t work out of the box).

Fortunately, there’s a helm chart for the metrics-server, so we can install it conveniently:

$ helm repo update
$ helm install --name my-metrics-server --set "args={--kubelet-insecure-tls}" stable/metrics-server --namespace my-metrics-server

After a few minutes (the time needed to gather some metrics) we should now be able to run kubectl top :

$ kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
docker-desktop 482m 24% 1408Mi 74%$ kubectl top pods --all-namespaces
NAMESPACE NAME CPU(cores) MEMORY(bytes)
kube-system etcd-docker-desktop 65m 42Mi
my-metrics-server my-metrics-server-7478b466f6-zjkxq 5m 13Mi
...

4. install the Kubernetes Dashboard webinterface

The Kubernetes Dashboard is the official WebUI for k8s. While it’s recommended to not have it installed on critical production clusters unless you have secured it properly, I find it especially useful for development and testing on my local single-node cluster as it gives a nice overview on resources, namespaces, etc.

Kubernetes Dashboard doesn’t ship out of the box with Docker Desktop, so we can add it ourselves:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc6/aio/deploy/recommended.yaml

We also need credentials to log in. For that we’ll create a service account and use its token to log into the webinterface. On the webinterface we’ll have privileges to do whatever the service account is allowed to do. As this is a disposable, locally running test cluster we’ll give it full control by making it a cluster admin.

First, to not pollute the default namespace, we’ll create a separate namespace for our dashboard user(s):

$ kubectl create namespace my-dashboard-sas

And then we’ll create the service account in it and give it the required privileges

$ kubectl -n my-dashboard-sas create serviceaccount my-dashboard-clusteradmin$ kubectl create clusterrolebinding my-dashboard-clusteradmin-role --clusterrole=cluster-admin --serviceaccount=my-dashboard-sas:my-dashboard-clusteradmin

Then, we’re ready to retrieve the token:

$ kubectl -n my-dashboard-sas get secrets
NAME TYPE DATA AGE
my-dashboard-clusteradmin-token-krvpb kubernetes.io/service-account-token 3 6m15s
...$ kubectl -n my-dashboard-sas describe secret my-dashboard-clusteradmin-token-krvpb
...
token: e1gRslo1pbrGs6z...
...

Now let’s open a channel from our client to the Kubernetes cluster to make the webinterface accessible on localhost

$ kubectl proxy

and open it in the browser from http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

and log in with method token and the secret we have retrieved above.

we select the “token” login method on the Kubernetes Dashboard login page

Now we can use the dashboard:

the Kubernetes Dashboard in action

(Note: We have to start kubectl proxy and leave it running every time we want to connect to the Dashboard. When we don’t need it anymore we can quit it by pressing CTRL + C. The login token is valid indefinitely — so we can i.e. store it in our browser’s password manager. If you ever see a “token expired” error message in the webinterface please check that kubectl proxy is running and/or restart it — that usually resolves it).

That’s it. We’re finally ready to do something useful with our local mini cluster!

poweruser.blog

notes from an occasional computer user

Follow

44

Kubernetes

Docker

Helm

Containers

DevOps

44 claps

Written by

Chris

Follow

Follow

poweruser.blog

Follow

notes from an occasional computer user

Follow

Written by

Chris

Follow

poweruser.blog

Follow

notes from an occasional computer user

See responses (2)

More From Medium

Storage housekeeping on Github Actions

Chris in poweruser.blog

Kubernetes ConfigMap Confuguration and Reload Strategy

Eresh Gorantla in The Startup

Using NodeSelector to Schedule Deployments with large volumes of Stateful Data on Kubernetes

Joseph D. Marhee

Traffic Mirroring in Kubernetes Using Istio

Gaurav Agarwal in Better Programming

Kubernetes Tips: Using a ServiceAccount

Luc Juggery in Better Programming

Sticky Sessions in Kubernetes

Zhimin Wen

Build GitHub Actions Using Docker Containers

Al-Waleed Shihadeh in Better Programming

Kubernetes External IP service type

Mohamad Fadhil in The Startup

Discover Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Make Medium yours

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Become a member

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

About

Help

Legal

Get the Medium app