Kubernetes Ingress service can not load static files

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 00:19:00

问题


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.


回答1:


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:

  • https://github.com/kubernetes/ingress-nginx/issues/333
  • https://github.com/kubernetes/contrib/issues/2238



回答2:


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.



来源:https://stackoverflow.com/questions/48394686/kubernetes-ingress-service-can-not-load-static-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!