Istio从入门到精通—— 流量治理的原理 —— VirutalService —— Headers

发布时间 2023-12-12 09:57:49作者: 左扬

流量治理的原理 —— VirutalService —— Headers

https://istio.io/latest/docs/reference/config/networking/virtual-service/#Headers

  Message headers can be manipulated when Envoy forwards requests to, or responses from, a destination service. Header manipulation rules can be specified for a specific route destination or for all destinations. The following VirtualService adds a test header with the value true to requests that are routed to any reviews service destination. It also removes the foo response header, but only from responses coming from the v1 subset (version) of the reviews service. 

Envoy 在将请求转发到或从目标服务响应时,可以操纵消息头。可以为特定路由目标或所有目标指定头操作规则。以下 VirtualService 向路由到任何 reviews 服务目标的请求添加一个值为 true 的测试头。它还会删除 foo 响应头,但仅从 reviews 服务的 v1 子集(版本)的响应中删除。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews-route
spec:
  hosts:
  - reviews.prod.svc.cluster.local
  http:
  - headers:
      request:
        set:
          test: "true"
    route:
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v2
      weight: 25
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v1
      headers:
        response:
          remove:
          - foo
      weight: 75
Field Type Description Required
request HeaderOperations

Header manipulation rules to apply before forwarding a request to the destination service

No
response HeaderOperations

Header manipulation rules to apply before returning a response to the caller

 No