Docker for Mac with Kubernetes — Enable K8S Dashboard

Thomas Hamm
2 min readJan 7, 2018

--

Have you just installed Docker for Mac beta and wonder how to access the Kubernetes UI? Read on…

As the Kubernetes UI is not installed by default, we are going to deploy it manually.

Before we start, make sure Kubernetes is up and running. Use kubectl cli to switch to the correct context.

$ kubectl config use-context docker-for-desktop

Next deploy all necessary objects like roles, services, … and the Dashboard deployment configuration to the cluster.

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

The dashboard will be deployed within the predefined kube-system namespace. Next check if the Dashboard Pod is running.

$ kubectl get pod --namespace=kube-system | grep dashboard
kubernetes-dashboard-7798c48646-2cdd7 1/1 Running 0 10h

Forward a local port (Port 8443) to the Pod. This is achieved by executing the kubectl port-forward command.

$ kubectl port-forward kubernetes-dashboard-7798c48646–2cdd7 8443:8443 --namespace=kube-system
Forwarding from 127.0.0.1:8443 -> 8443

Open a browser and navigate to https://localhost:8443 and skip the Dashboard authentication config.

Alternative: For a more permanent solution, rather than always executing the “port-forward” command a “NodePort” can be used to allocate a port on the local machine running the Kubernetes node.

Configure a service with type “NodePort”. This port will be accessible on localhost. Create a file called “k8s-dashboard-nodeport-service.yaml” like

apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-nodeport
namespace: kube-system
spec:
ports:
— port: 8443
protocol: TCP
targetPort: 8443
nodePort: 31234
selector:
k8s-app: kubernetes-dashboard
sessionAffinity: None
type: NodePort

and upload the service to Kubernetes.

$ kubectl create -f k8s-dashboard-nodeport-service.yaml

Check if the service is available.

$ kubectl get service --namespace=kube-system | grep kubernetes-dashboard-nodeport
kubernetes-dashboard-nodeport NodePort 10.97.109.224 <none> 8443:31234/TCP 25m

From now on the dashboard will always be avaliable on https://localhost:31234.

Have fun.

--

--