Kubernetes Ingress service can not load static files

1/23/2018

I have created ingress for some services on minikube (1.8.0):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: gateway-ingress
  namespace: kube-system
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: api-service
          servicePort: 80
        path: /api
      paths:
      - backend:
          serviceName: kubernetes-dashboard
          servicePort: 80
        path: /ui

When I access MINIKUBE_IP/ui, the static files of dashboard not work. Below are errors:

192.168.99.100/:1 GET https://192.168.99.100/ui/static/vendor.4f4b705f.css net::ERR_ABORTED
192.168.99.100/:5 GET https://192.168.99.100/ui/static/app.8a6b8127.js net::ERR_ABORTED
VM1524:1 GET https://192.168.99.100/ui/api/v1/thirdpartyresource 404 ()
...

Please help me to fix this error, thanks.

-- WorkWe
kubectl
kubernetes
minikube

2 Answers

7/16/2018

I had the same issue. You can solve it by defining new paths in the Ingress resource.

 rules:
  - http:
      paths:
      - path: /ui
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 80
      - path: /*
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 80

The "/*" will allow you to access the static files.

Other resources:

-- Alberto Castelo Becerra
Source: StackOverflow

12/13/2018

Add the following line to annotation: ingress.kubernetes.io/add-base-url: "true" solves this problem.

If you use - path: /*, everything will populate under /. And connect directly to http://<host_ip> will end up getting the same as http://<host_ip>/ui, which is probably not ideal result.

-- Lita
Source: StackOverflow