当您使用rewrite 时,您需要在虚拟服务中为您的依赖项(如 css 和 js)添加路径。
@Rinor here 很好地解释了重写的整个过程以及应该如何配置。
这个Istio in practise 教程也很好解释。
让我们分解应该路由到前端的请求:
确切路径 / 应该路由到前端以获取 Index.html
前缀路径 /static/* 应该被路由到前端以获取前端所需的任何静态文件,例如 层叠样式表 和 JavaScript 文件强>。
匹配正则表达式 ^.*.(ico|png|jpg)$ 的路径应路由到前端,因为它是页面需要显示的图像。
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 path ,这里什么都没有,因为真正的路径是/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