我想根据标头将流量路由到 Pod - 有后备。
期望的结果是一个 k8s 集群,其中可以部署同一服务的多个版本并使用标头值路由到该集群。
svcA svcB svcC
这些服务(git repo 的主要分支)中的每一个都将部署到默认命名空间或标记为“main”。每个服务的任何功能分支也可以部署到它自己的命名空间中或用分支名称标记。
理想情况下,通过将标头 X-svcA
设置为与分支名称匹配的值,我们会将任何流量路由到匹配的命名空间或标签。如果没有这样的命名空间或标签,则将流量路由到默认(主)pod。
if HEADERX && svcX:label
route->svcX:label
else
route->svcX
第一个问题 - 这(或类似)是否可以使用 istio 或 linkerd
答案 0 :(得分: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。
答案 1 :(得分: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"
},
}