Skip to content

How to access Microk8s dashboard without proxy

In getting started with Microk8s on ubuntu I walked through the process of installing and configuring Microk8s on a stand-alone server and also how to access the Dashboard via the proxy.

This works great, however it can be annoying because every time you want to access the dashboard you have to remember to terminal onto the box and enable it to use. This gets really annoying really quickly especially when you starting to use kubernetes more and more as you’re learning.

Ideally it would be great if we could just access the Dashboard anytime we need it. After playing around for sometime I figured out how to do this.

Information

In the getting started with Microk8s on ubuntu I also cover some convenient configurations options you may find handy, as in how to execute kubectl commands without having to use microk8s

Enable additional Add-Ons

We will need to enable a few additional Kubernetes add-ons to get this functionality up and running.

microk8s enable ingress       # Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster.
microk8s enable dashboard     # web-based Kubernetes user interface
microk8s enable dns           # creates DNS records for services and pods
microk8s enable storage       # provide both long-term and temporary storage to Pods in your cluster.

Advice

In Getting started with MicroK8s on Ubuntu I also provided instructions on how to Add User Account Microk8s to enable executing microk8s commands without sudo that is why I am able to execute the above commands. If you have not done this then you will need to prefix the commands with sudo

There is not much more configuration we need to do other enable these plugins

Enable Host Access

We need to alos enable one more additional add-on host-access to enable the access to services running on the host machine via fixed IP address.

We can enable to make use of the default address

microk8s enable host-access

Edit Kubernetes Dashboard Service

We need to edit the kubernetes-dashboard service file which provides dash-board functionality. To to edit this we need to edit dashboard service and change service “type” from ClusterIP to NodePort.

We use the following command to edit the file using vim.

kubectl -n kube-system edit service kubernetes-dashboard

This should open the contents of the file in vim and it should look something similar file below

You need to change type to NodePort

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard","namespace":"kube-system"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"}}}
  creationTimestamp: "2022-03-09T14:10:50Z"
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
  resourceVersion: "1029725"
  selfLink: /api/v1/namespaces/kube-system/services/kubernetes-dashboard
  uid: b2608643-a712-4b44-abad-160cf140df49
spec:
  clusterIP: 10.152.183.220
  clusterIPs:
  - 10.152.183.220
  externalTrafficPolicy: Cluster
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - nodePort: 30536
    port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: clusterIP                  ## Change this to NodePort
status:
  loadBalancer: {}

Once you save and exit the file K8s will automatically restart the service.

We can then get the Port the service is running by using the following command

kubectl -n kube-system get services

Which should display something similar to the below and which we can see that the Dashboard is available on port 30536 in my case

NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
metrics-server              ClusterIP   10.152.183.108   <none>        443/TCP                  7d4h
dashboard-metrics-scraper   ClusterIP   10.152.183.170   <none>        8000/TCP                 7d4h
kube-dns                    ClusterIP   10.152.183.10    <none>        53/UDP,53/TCP,9153/TCP   7d4h
kubernetes-dashboard        NodePort    10.152.183.220   <none>        443:30536/TCP            7d4h

We can now open our Firefox browser on any workstation on our network and navigate to https://{server ip}:{port number} in my case it is https://192.168.0.35:30536

Get the token

We need to get the token from the server so we can do so using the following command in the server terminal

token=$(kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
kubectl -n kube-system describe secret $token

This should return something similar too

Copy the token text and paste it into the login dialog in the browser

Then you should be able to login with ease.

Conclusion

Using the above approach will enable access to the Kubernetes dashboard a web-based user interface. You can use Dashboard to deploy containerised applications to a Kubernetes cluster, troubleshoot your containerised application, and manage the cluster resources. You can use Dashboard to get an overview of applications running on your cluster, as well as for creating or modifying individual Kubernetes resources (such as Deployments, Jobs, DaemonSets, etc). For example, you can scale a Deployment, initiate a rolling update, restart a pod or deploy new applications using a deploy wizard.