gpt4 book ai didi

docker - 如何在一个 Istio 服务网格中托管多个应用程序?

转载 作者:行者123 更新时间:2023-12-02 09:23:26 28 4
gpt4 key购买 nike

我正在设置一个 Istio 服务网格,其中有两个服务都运行 Graphql 引擎。我计划将它们设置在两个不同的子路径上。您将如何在 VirtualService 上设置重定向?

我已经尝试使用此 VirtualService 配置

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: hasura-1
spec:
hosts:
- "*"
gateways:
- hasura-gateway
http:
- match:
- uri:
prefix: /hasura1
route:
- destination:
host: hasura-1
port:
number: 80
- match:
- uri:
prefix: /hasura2
route:
- destination:
host: hasura-2
port:
number: 80

但每当我尝试访问这些前缀时,我总是会遇到错误 404。

编辑:我已更新我的虚拟服务以合并 rewrite.uri。每当我尝试访问任一前缀时,我都会被重定向到 / 并给出错误 404。这是我更新的网关和 VirtualService list 。

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: hasura-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: hasura-1
spec:
hosts:
- "*"
gateways:
- hasura-gateway
http:
- match:
- uri:
exact: /hasura1
rewrite:
uri: /
route:
- destination:
host: hasura-1
port:
number: 80
- match:
- uri:
exact: /hasura2
rewrite:
uri: /
route:
- destination:
host: hasura-2
port:
number: 80
---

最佳答案

您的 Hasura 的 GraphQL 端点配置在什么路径上?

根据 VirtualService 的配置方式,对网关的请求将如下所示:

my.host.com/hasura1 --> hasura-1/hasura1
my.host.com/hasura1/anotherpath --> hasura-1/hasura1/anotherpath
my.host.com/hasura2 --> hasura-2/hasura2

也许您缺少用于从请求中删除路径的 rewrite.uri 规则。

例如:使用此规则:

http:
- match:
- uri:
prefix: /hasura1
rewrite:
uri: /
route:
- destination:
host: hasura-1
port:
number: 80

您的 Hasura 容器应该接收根路径上的请求:

my.host.com/hasura1 --> hasura-1/
my.host.com/hasura1/anotherpath --> hasura-1/anotherpath

关于docker - 如何在一个 Istio 服务网格中托管多个应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55515081/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com