【问题标题】:Dynamic header based routing with fallback基于动态标头的路由和回退
【发布时间】:2021-08-02 07:10:14
【问题描述】:

我想根据标头将流量路由到 pod - 带有后备。

期望的结果是一个 k8s 集群,其中可以部署同一服务的多个版本并使用标头值路由到该集群。

svcA 服务端 svcC

这些服务中的每一个(git repo 的主分支)都将部署到默认命名空间或标记为“main”。每个服务的任何功能分支也可以部署到其自己的命名空间中或标有分支名称。

理想情况下,通过将标头 X-svcA 设置为与分支名称匹配的值,我们会将任何流量路由到匹配的命名空间或标签中。如果没有这样的命名空间或标签,则将流量路由到默认(主)pod。

if HEADERX && svcX:label 
    route->svcX:label
else
    route->svcX 

第一个问题 - istio 或 linkerd 是否可以实现(或类似的)

【问题讨论】:

    标签: kubernetes istio linkerd


    【解决方案1】:

    您可以使用 Istio VirtualService 来做到这一点

    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    ...
    spec:
      hosts:
      - reviews
      http:
      - match:
        - headers:
            end-user:
              exact: jason
        route:
        - destination:
            host: reviews
            subset: v2
      - route:
        - destination:
            host: reviews
            subset: v1
    

    阅读更多here

    【讨论】:

    • 谢谢瓦西里。我认为我的评论与我对 Harsh Manvar 的回复类似。这些已定义 - 我希望有一个动态解决方案,以便每次我们希望基于其分支部署服务的新实例时都不需要更新此配置。在 istio 或 linkerd 中是否有类似和 IF 的构造?
    • 我几乎不相信使用普通的 Kubernetes 和 Istio 可以做到这一点。但我认为它可以在 CI/CD 管道中实现自动化。
    【解决方案2】:

    是的,您可以使用 Istion 和 Linkerd 根据标头路由请求

    关于 istio 有一篇不错的文章:https://dwdraju.medium.com/simplified-header-based-routing-with-istio-for-http-grpc-traffic-ff9be55f83ca

    在 istio 的虚拟服务中,您可以像这样更新标头:

    http:
      - match:
        - headers:
            x-svc-env:
              regex: v2
    

    对于链接器:

    Kind = "service-router"
    Name = "service"
    Routes = [
      {
        Match {
          HTTP {
            PathPrefix = "/api/service/com.example.com.PingService"
          }
        }
        Destination {
          Service       = "pinging"
        },
      },
      {
        Match {
          HTTP {
            PathPrefix = "/api/service/com.example.com.PingService"
            Header = [
              {
                Name  = "x-version"
                Exact = "2"
              },
            ]
          }
        }
        Destination {
          Service       = "pinging"
          ServiceSubset = "v2"
        },
      }
    

    【讨论】:

    • 据我了解 - 这些必须定义。我真的很想要一个动态的解决方案 - 即我不必去定义新的目的地 - 如果目的地存在,它会路由到目的地,如果不路由到“主”吊舱?这可能吗?
    猜你喜欢
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多