gpt4 book ai didi

Istio VirtualService HTTP header 匹配问题

转载 作者:行者123 更新时间:2023-12-04 16:00:17 25 4
gpt4 key购买 nike

以下 Istio 0.8 VirtualService 无法匹配 HTTP header 。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- match:
- headers:
foo:
exact: bar
route:
- destination:
host: reviews
subset: v2
- route:
- destination:
host: reviews
subset: v3

我关注了https://github.com/istio/issues/issues/38Istio RouteRule based on headers user-agent doesn't work .但是我无法让它发挥作用。

指针会非常有用,因为 sleep 服务会返回类似于 POSTMAN 的产品页面,而不会暗示匹配条件!

最佳答案

如果您没有 DestinationRule 来定义您的子集(版本),则此 VirtualService 本身将无法工作。

我将演示如何使用 0.8 版本附带的 HelloWorld 示例完成此操作:

第 1 步:部署 samples/helloworld/helloworld.yaml

第 2 步:为两个可用版本定义一个 DestinationRule:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: helloworld
spec:
host: helloworld
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2

第 3 步:将默认的 VirtualService 替换为与路由 header 属性匹配的服务:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: helloworld
spec:
hosts:
- "*"
gateways:
- helloworld-gateway
http:
- match:
- headers:
foo:
exact: bar
route:
- destination:
host: helloworld
subset: v2
- route:
- destination:
host: helloworld
subset: v1

第 4 步:测试:

  • 没有 header :curl http://$INGRESS_GATEWAY/hello

    输出:

    Hello version: v1, instance: helloworld-v1-fd9b784bb-wcnj9

  • 带有 header :curl -H "foo: bar"http://$INGRESS_GATEWAY/hello

    输出:

    Hello version: v2, instance: helloworld-v2-56694b7d6d-gbhqb

关于Istio VirtualService HTTP header 匹配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50682919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com