【问题标题】:Istio: single gateway and multiple VirtualServices (each one in a different namespace)Istio:单个网关和多个 VirtualService(每个都在不同的命名空间中)
【发布时间】:2021-04-15 14:55:32
【问题描述】:

如何在 Istio 1.9 中设置单个网关和多个 VirtualService(每个都在不同的命名空间中)。 我不能为每个虚拟服务设置一个网关,因为浏览器利用 HTTP/2 connection reuse 产生 404 错误。

如果我关注these instructions,它将无法正常工作,因为网关和虚拟服务不能位于不同的命名空间中。

这些是清单文件:

APP1:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: app1-gateway
  namespace: app1
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "app1.example.com"
    tls:
      httpsRedirect: true # sends 301 redirect for http requests
  - port:
      number: 443
      name: https-app1
      protocol: HTTPS
    tls:
      mode: SIMPLE
      credentialName: sslcertificate
    hosts:
    - "app1.example.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: app1
  namespace: app1
spec:
  hosts:
  - "app1.example.com"
  gateways:
  - app1-gateway
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: app1
        port:
          number: 80

APP2:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: app2-gateway
  namespace: app2
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "app2.example.com"
    tls:
      httpsRedirect: true # sends 301 redirect for http requests
  - port:
      number: 443
      name: https-app2
      protocol: HTTPS
    tls:
      mode: SIMPLE
      credentialName: sslcertificate
    hosts:
    - "app2.example.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: app2
  namespace: app2
spec:
  hosts:
  - "app2.example.com"
  gateways:
  - app2-gateway
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: app2
        port:
          number: 80

【问题讨论】:

  • because gateway and virtualservice can't be in different namespaces,实际上它们可以在不同的命名空间中。查看 istio documentation 上的第一个和第二个示例。您只需在虚拟服务网关中指定命名空间,例如gateways: - some-namespace/app-gateway
  • 你救了我的命,这正是我所寻找的。谢谢

标签: kubernetes istio istio-gateway


【解决方案1】:

回答你的问题,because gateway and virtualservice can't be in different namespaces,实际上它们可以位于不同的命名空间中。

如果它与虚拟服务不在同一个命名空间中,您只需在虚拟服务spec.gateways 中指定该命名空间。

查看spec.gateways 部分

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo-Mongo
  namespace: bookinfo-namespace
spec:
  gateways:
  - some-config-namespace/my-gateway # can omit the namespace if gateway is in same
                                       namespace as virtual service.

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
  namespace: some-config-namespace

有相关的istio documentation关于那个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 2019-05-25
    • 2020-11-17
    • 1970-01-01
    • 2020-09-21
    • 2019-03-14
    • 2013-02-17
    相关资源
    最近更新 更多