VirutualService,但测试发现定义的规则似乎没有生效,通常是一些配置问题,本文列举一下常见的可能原因。VirutualService 没有指定 gateways 字段,实际隐含了一层意思,istio 会默认加上一个叫 “mesh” 的保留 Gateway,表示集群内部所有 Sidecar,也就表示此 VirutualService 规则针对集群内的访问生效。gateways 字段,istio 不会默认加上 “mesh”,如:apiVersion: networking.istio.io/v1beta1kind: VirtualServicemetadata:name: productpagespec:gateways:- istio-test/test-gatewayhosts:- bookinfo.example.comhttp:- route:- destination:host: productpageport:number: 9080
VirualService 规则仅对 istio-test/test-gateway 这个 Gateway 生效,如果是在集群内访问,流量不会经过这个 Gateway,所以此规则也就不会生效。gateways 显式指定上 “mesh”:gateways:- istio-test/test-gateway- mesh
VirutualService 不仅对 istio-test/test-gateway 这个 Gateway 生效,也对集群内部访问生效。
hosts 就需要加上访问集群内的 service 名称:hosts:- bookinfo.example.com- productpage
Gateway 和 VirtualService 中的 hosts 均包含实际访问用到的 Host 或使用通配符能匹配得上,通常是外部域名。404 Not Found,正确示例:apiVersion: networking.istio.io/v1alpha3kind: Gatewaymetadata:name: test-gatewaynamespace: istio-testspec:selector:app: istio-ingressgatewayistio: ingressgatewayservers:- port:number: 80name: HTTP-80-wwwprotocol: HTTPhosts:- bookinfo.example.com # 这里定义外部访问域名---apiVersion: networking.istio.io/v1beta1kind: VirtualServicemetadata:name: productpagespec:gateways:- istio-test/test-gatewayhosts:- bookinfo.example.com # 这里也要定义外部访问域名http:- route:- destination:host: productpageport:number: 9080
文档反馈