istio - Istio VirtualService HTTP 标头匹配问题
问题描述
以下 Istio 0.8 VirtualService 无法匹配 HTTP 标头。
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/38并且基于标头用户代理的 Istio RouteRule 不起作用。但是我无法让它发挥作用。
指针会非常有用,因为 sleep 服务会返回类似于 POSTMAN 的产品页面,而不会暗示匹配条件!
解决方案
如果您没有DestinationRule
定义子集(版本),则此 VirtualService 本身将不起作用。
我将演示如何使用 0.8 版本中包含的 HelloWorld 示例来完成它:
第 1 步:部署samples/helloworld/helloworld.yaml
第 2 步:DestinationRule
为两个可用版本定义 a :
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
与路由的标头属性匹配的值:
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步:测试它:
没有标题:
curl http://$INGRESS_GATEWAY/hello
输出:
你好版本:v1,实例:helloworld-v1-fd9b784bb-wcnj9
带标题:
curl -H "foo: bar" http://$INGRESS_GATEWAY/hello
输出:
你好版本:v2,实例:helloworld-v2-56694b7d6d-gbhqb
推荐阅读
- sql - 有人可以解释为什么这个查询不起作用吗?
- c - 如何检查 /proc/net 中的网络条目是否存在于 C 中?
- react-native - 样式组件未正确安装到 react-native 项目
- python - 通过添加小数时间增量增量来消除重复的日期时间索引值
- arcgis - 为什么当 arcgis rest update 数据时 SQL Server arcgis 表数据不更新?
- angular - 'Point | 类型不存在属性'percentage' 系列'
- mysql - 为什么在 mysql 上限偏移情况下查询所有列比仅查询 id 列慢?
- mongodb - 使用 AWS S3 存储桶作为 mongodb 数据路径时,Mongodb 未启动
- sql - 优化 SQL 查询以获得更好的集群性能并降低磁盘利用率
- pine-script - 无法应用 Label.delete 功能