Microk8s: [dashboard] should be exposed via ingress

Created on 10 Jan 2020  路  6Comments  路  Source: ubuntu/microk8s

When running microk8s on the server, rather than doing port forwarding it should be possible to access the dashboard via ingress (similar to kubeflow dashboard)

enhancement good first issue help wanted

All 6 comments

Thank you for this request, it is brought up frequently. We need to address the need for easy access to the dashboard in a secure way. Until we do so, to access the dashboard have a look at the MicroK8s docs [1] and the dashboard upstream wiki [2]

[1] https://microk8s.io/docs/addon-dashboard
[2] https://github.com/kubernetes/dashboard/blob/master/docs/user/accessing-dashboard/1.7.x-and-above.md

So it's 2020 and this still hasn't been solved yet?

Enable the ingress addon:
microk8s enable ingress

and create an ingress ressource:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
  name: dashboard
  namespace: kube-system
spec:
  rules:
  - http:
      paths:
      - path: "/dashboard/?(.*)"
        pathType: Prefix
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 443

Now you can access the dashboard with http://<Microk8s-IP>/dashboard/

Enable the ingress addon:
microk8s enable ingress

and create an ingress ressource:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
  name: dashboard
  namespace: kube-system
spec:
  rules:
  - http:
      paths:
      - path: "/dashboard/?(.*)"
        pathType: Prefix
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 443

Now you can access the dashboard with http://<Microk8s-IP>/dashboard/

Following these instructions I can access http:///dashboard/ but the page doesn't load correctly because the assets (styling, js, images) cannot be resolved correctly (404).

Screenshot from 2020-12-07 20-38-37

Manually appending /dashboard/ to the asset path fixes this issue. Any workaround?

This works for me (microk8s 1.19):

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dashboard
  namespace: kube-system
  annotations:
    # use the shared ingress-nginx
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^(/dashboard)$ $1/ redirect;
spec:
  # https://kubernetes.io/docs/concepts/services-networking/ingress/
  # https://kubernetes.github.io/ingress-nginx/user-guide/tls/
  rules:
  - http:
      paths:
      - path: /dashboard(/|$)(.*)
        pathType: ImplementationSpecific
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 443

Thanks Rom888, works for me too. Other than in my microk8s I need to use Ingress class: public

I1225 18:15:43.940765       6 flags.go:205] Watching for Ingress class: public
W1225 18:15:43.940833       6 flags.go:208] Only Ingresses with class "public" will be processed by this Ingress controller
Was this page helpful?
0 / 5 - 0 ratings