【问题标题】:How to host multiple applications in one Istio service mesh?如何在一个 Istio 服务网格中托管多个应用程序?
【发布时间】:2019-08-26 03:48:41
【问题描述】:

我正在设置一个 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 清单。

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
---

【问题讨论】:

  • 显然,您的VirtualService 没问题。您能否提供用于创建hasura-gateway 的清单? hasura-1hasura-2 Kubernetes 服务的清单也会很有用。
  • @eduardo-baitello 我在编辑后的帖子中添加了hasura-gateway 的清单。对于hasura-1hasura-2 的清单,我只是结合了在Hasura 的GKE 教程here 中找到的deployment.yamlservice.yaml,并在服务清单中删除了type.uri
  • 嗨,基恩。嗯...Gateway 看起来不错。你能模拟请求并从istio-ingresshasura-x 服务下的容器中检索日志吗?我们需要知道是谁返回了 404。
  • 嗨,基恩。有这方面的更新吗?
  • hasura-1hasura-2 服务是否在同一个命名空间中?如果不是,则应该是 destination 字段中它们的完全限定名称,然后是 (.)

标签: docker kubernetes graphql istio hasura


【解决方案1】:

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

【讨论】:

  • 你说得对,我计划在 /hasura1/hasura2 配置我的 GraphQL 端点。我尝试像这样设置 rewrite.uri 但在两个前缀中我都被重定向到 / 并给出错误 404。我认为它能够访问图像,因为它通过 @ 向前重定向987654338@ 但它在错误 404 处停止。而不是这样:my.host.com/hasura1 --> hasura-1/ 它像这样经历:my.host.com/hasura1 --> my.host.com/ 我编辑了我的帖子以更新虚拟服务,并且还有网关清单。
  • 嗨@Eduardo Baitello,问题在于用于服务的图像不接受/console以外的任何路由,这就是它发出错误404的原因。我们没有确实需要将其他 pod 公开为路由,这就是为什么我们只有一个 pod 在网关内提供服务。为了让它访问其他 pod,我应用了@Anna Slastnikova 评论,现在它可以工作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-28
  • 1970-01-01
  • 2018-11-18
  • 1970-01-01
  • 2023-03-17
  • 2019-08-15
  • 2019-08-05
相关资源
最近更新 更多