kubernetes - Istio:单个网关和多个 VirtualServices(每个都在不同的命名空间中)
问题描述
如何在 Istio 1.9 中设置单个网关和多个 VirtualService(每个都在不同的命名空间中)。我不能为每个虚拟服务设置一个网关,因为浏览器利用 HTTP/2连接重用来产生 404 错误。
如果我按照这些说明进行操作,它将无法工作,因为网关和虚拟服务不能位于不同的命名空间中。
这些是清单文件:
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
实际上它们可以位于不同的名称空间中。
如果它与虚拟服务不在同一个命名空间中,则只需在虚拟服务中指定该命名空间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 文档。
推荐阅读
- python - 使用单独的数据帧手动计算预测
- ios - 如何在将文件上传到 Firebase 存储时暂停执行
- if-statement - 多个 If 查询语句?
- r - 如何在 RcppArmadillo 中同时使用 OpenMP 和 OpenBlas?
- asp.net-core - ASP.NET CORE:可以查询是作为 Windows 服务运行还是作为控制台应用程序运行?
- python - 在 python 中执行统计分析
- amazon-web-services - 如何监控 AWS 子网中的 IP 分配?
- sql-server - SQL Server 存储过程作为输入错误
- julia - 如何使用 Julia 处理 CSV?
- javascript - 在使用 React-Hooks 时,我在 React 代码中获得了无限的重新渲染。我该如何解决这个问题?