带有网状网关的 Istio VirtualService 委托

时间:2021-01-19 15:59:46

标签: istio

我正在为一组内部服务实现一些路由逻辑,其中委托 VirtualService 看起来是一个不错的解决方案:

https://istio.io/latest/docs/reference/config/networking/virtual-service/#Delegate

我创建了一些类似于文档中的测试设置,只有一个区别。就我而言,绑定到“网状”网关的“根”VirtualService 和“主机”则是一些内部服务名称。这应该有效还是委派仅适用于非网状网关?

这是根 VirtualService(想法是所有请求都发送到 worker-pool.default.svc.cluster.local,然后根据某些 HTTP 标头将它们转发到其他 VirtualService):

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: worker-pool
spec:
  hosts:
  - worker-pool.default.svc.cluster.local
  http:
    - name: "route 1"
      match:
        - headers:
            customer-id:
              exact: alice
      delegate:
        name: worker-for-alice
    - name: "route 2"
      match:
        - headers:
            customer-id:
              exact: bob
      delegate:
        name: worker-for-bob

这里是另一个 VirtualService(只显示一个,两者看起来一样):

apiVersion: v1
kind: Service
metadata:
  name: worker-for-alice
  labels:
    app: worker-for-alice
    service: worker-for-alice
spec:
  ...
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: worker-for-alice
spec:
  http:
  - route:
    - destination:
        host: worker-for-alice

1 个答案:

答案 0 :(得分:0)

我想有几点需要考虑:

  1. 就我而言,Delegate 仅适用于网关。所以,你应该需要这样的东西:
spec:
  gateways:
  - mesh
  hosts:
  - worker-pool.default.svc.cluster.local
  http:
  ...
  1. 使用命名空间总是一个好主意。在命名空间中定义项目后,将“命名空间”元素添加到委托定义中:
      delegate:
        name: worker-for-bob
        namespace: <some-namespace>
  1. 最后但并非最不重要的一点是,可能需要在 istiod 配置中将变量 PILOT_ENABLE_VIRTUAL_SERVICE_DELEGATE 设置为“true”:
kubectl edit deployment istiod -n istio-system

然后在spec.template.spec.container.env中添加这个env变量