我正在尝试使用 Istio 在不同命名空间中的应用程序之间建立平衡。但我总是从 dev 命名空间中的一个应用程序得到回复。我的观点是从相同前缀的应用程序中获取响应,例如: http://example.com - 需要在命名空间之间进行平衡
dev
、staging
、production
我在不同的命名空间中部署了
VirtualService
、DestinationRule
和 Gateway
。我还尝试在 Gateway
命名空间中部署一个 istio-system
并在所有 VirtualService
中设置正确的路径。
显然我不明白它是如何工作的......
我的VirtualService
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-nginx-vs
namespace: dev
spec:
hosts:
- xxx.elb.amazonaws.com
gateways:
- dev/istio-nginx-gw
http:
- route:
- destination:
host: istio-nginx.dev.svc.cluster.local
port:
number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-nginx-vs
namespace: staging
spec:
hosts:
- xxx.elb.amazonaws.com
gateways:
- staging/istio-nginx-gw
http:
- route:
- destination:
host: istio-nginx.staging.svc.cluster.local
port:
number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-nginx-vs
namespace: production
spec:
hosts:
- xxx.elb.amazonaws.com
gateways:
- production/istio-nginx-gw
http:
- route:
- destination:
host: istio-nginx.production.svc.cluster.local
port:
number: 80
这里是
DestinationRule
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: istio-nginx-dr
namespace: dev
spec:
host: istio-nginx.svc.dev.cluster.local
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: istio-nginx-dr
namespace: staging
spec:
host: istio-nginx.staging.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: istio-nginx-dr
namespace: production
spec:
host: istio-nginx.production.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
还有
Gateway
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: istio-nginx-gw
namespace: dev
spec:
selector:
app: istio-gateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- xxx.elb.amazonaws.com
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: istio-nginx-gw
namespace: staging
spec:
selector:
app: istio-gateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- xxx.elb.amazonaws.com
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: istio-nginx-gw
namespace: production
spec:
selector:
app: istio-gateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- xxx.amazonaws.com
由于不同命名空间的不同网关定义中的主机“xxx.elb.amazonaws.com”值对于“istio-nginx”服务是相同的。因此只会应用一条路由规则。因此,这些请求将由单个应用程序提供服务。有关路由规则优先级的更多详细信息可以参考 istio 文档
使用“istioctl”工具可以验证配置的路由。
istioctl pc routes deploy/istio-ingressgateway.istio-system | grep "istio-nginx"