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

问题描述 投票:3回答:1

我在运行Graphql引擎的内部设置了两个服务的Istio服务网格。我打算将它们设置在两个不同的子路径上。您将如何在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.这是我更新的Gateway和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
---
docker kubernetes graphql istio hasura
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.