帮助!
我正在使用 Istio 在 Kubernetes 中设置服务网格。虚拟服务定义将流量路由到所需的服务:
(...)
http:
- match:
- uri:
prefix: /drill/
rewrite:
uri: /
route:
- destination:
host: drill-service.drill.svc.cluster.local
port:
number: 8047
但是,调用入口点时
https://<HOST>:<NODEPORT_INGRESS_GW>/drill
我确实看到了 HTML 页面,但 URL 已损坏且 CSS 表未正确加载。原因是 HTML 源代码指向了错误的目标:
li><a href="/storage">Storage</a></li>
代替
li><a href="/drill/storage">Storage</a></li>
我该如何解决这个问题?
谢谢,
马特
最佳答案
当您使用 rewrite 时您需要在虚拟服务中为您的依赖项(如 css 和 js)添加路径。
@Rinor here 很好地解释了重写的整个过程以及应该如何配置它.
这Istio in practise tutorial也解释的很好。
Let’s break down the requests that should be routed to Frontend:
Exact path / should be routed to Frontend to get the Index.html
Prefix path /static/* should be routed to Frontend to get any static files needed by the frontend, like Cascading Style Sheets and JavaScript files.
Paths matching the regex ^.*.(ico|png|jpg)$ should be routed to Frontend as it is an image, that the page needs to show.
http:
- match:
- uri:
exact: /
- uri:
exact: /callback
- uri:
prefix: /static
- uri:
regex: '^.*\.(ico|png|jpg)$'
route:
- destination:
host: frontend
port:
number: 80
另外你可以看看here .
编辑
为什么你的例子不起作用
对于您当前的虚拟服务,您的请求如下:
http://www.page.com/drill/
Rewritten: http://www.page.com/
http://www.page.com/drill/storage
Rewritten: http://www.page.com/storage
所以现在您必须更改虚拟服务配置,例如不重写的路径或更改您的应用程序依赖项位置,这样 istio 实际上可以看到 /drill/storage
路径与您当前的虚拟服务,现在它看到的是 /storage
路径,这里什么也没有,因为真正的路径是 /drill/storage
。
http:
- match:
- uri:
prefix: /
- uri:
prefix: /drill/storage/
- uri:
prefix: /...
我的建议
如果您将域配置为虚拟服务主机,您可以尝试使用此虚拟服务:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-vs
spec:
hosts:
- "drill.domain.com"
gateways:
- gateway
http:
- match:
- uri:
prefix: /
rewrite:
uri: /drill/
route:
- destination:
host: drill-service.drill.svc.cluster.local
port:
number: 8047
使用此虚拟服务,您的请求如下:
http://www.page.com/
Rewritten: http://www.page.com/drill/
http://www.page.com/storage
Rewritten: http://www.page.com/drill/storage
关于url - Istio VirtualService - 损坏的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65213843/