Huy Chau
Huy Chau

Reputation: 2240

Kubernetes Ingress service can not load static files

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.

Upvotes: 4

Views: 8895

Answers (2)

Lita
Lita

Reputation: 75

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.

Upvotes: 2

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:

Upvotes: 5

Related Questions