用例: 我有两个服务在带有Istio 1.0
的本地 k8s 集群上运行,即带有port: 5601
的 Kibana 和带有port:3000
的Grafana
。
需要使用基于路径的路由来路由这些服务。期望是,使用单个网关需要使用路径分离来访问这两个服务。
示例:http://172.16.22.233:31380/kibana 和 http://172.16.22.233:31380/grafana
我尝试了以下配置,但它不起作用。
网关.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway
spec:
selector:
istio: ingressgateway # use istio default ingress gateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
`
virtualservice.yaml
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs
spec:
hosts:
- "*"
gateways:
- gateway
http:
- match:
- uri:
prefix: "/kibana"
route:
- destination:
port:
number: 5601
host: kibana
- match:
- uri:
prefix: "/grafana"
route:
- destination:
port:
number: 3000
host: grafana
`
有人可以建议网关和虚拟服务资源的配置吗?
如果你请求http://172.16.22.233:31380/kibana
,你的虚拟服务将路由到 kibana,但它也会将请求路径转发/kibana
。我不确定这是做什么的,但发送 404 响应将是我的猜测。
如果要访问根页面/
,则需要在规则中添加rewrite
字段:
- match:
- uri:
prefix: "/kibana"
rewrite:
uri: /
route:
- destination:
port:
number: 5601
host: kibana