【问题标题】:Istio VirtualService delegate with mesh gateway带有网状网关的 Istio VirtualService 委托
【发布时间】:2021-04-23 23:06:39
【问题描述】:

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

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

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

这是根 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

【问题讨论】:

  • 嘿@F7502,是的,代理应该使用网状网关。 curl -v worker-pool/ 的输出是什么?您能否尝试将delegate 更改为route,以便使用单个虚拟服务并检查它是否有效?从我的角度来看,delegate 可能不适用于标头,因为它适用于 uri,您可以阅读有关它的更多信息here

标签: istio


【解决方案1】:

我想有几点需要考虑:

  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 变量

【讨论】:

    猜你喜欢
    • 2021-08-10
    • 1970-01-01
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    相关资源
    最近更新 更多