2

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

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

svcA svcB svcC

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

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

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

第一个问题 - istio 或 linkerd 是否可能(或类似的东西)

4

2 回答 2

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

在这里阅读更多。

于 2021-05-12T05:24:02.940 回答
0

是的,您可以使用 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"
    },
  }
于 2021-05-12T05:47:27.203 回答