带有回退的基于动态标头的路由

问题描述

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

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

svcA svcB svcC

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

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

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

一个问题 - 这(或类似)是否可​​以使用 istio 或 linkerd

解决方法

您可以使用 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

,

是的,您可以使用 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"
    },}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...