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

流量治理的原理 —— 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 // 指定了一个 VirtualService 名称 "reviews-route"。
spec:
  hosts:
  - reviews.prod.svc.cluster.local  // 指定了一个主机名 "reviews.prod.svc.cluster.local"
  http:
  - headers:  // 定义了请求头的操作。
      request:  // 定义了请求头的设置。
        set:    // 设置请求头
          test: "true"    // 设置了一个名为 "test" 的请求头,其值为 "true"。
    route:      // 定义了要路由到的目标服务列表。
    - destination:
        host: reviews.prod.svc.cluster.local  // 目标服务的主机名被指定为 "reviews.prod.svc.cluster.local"。
        subset: v2    // 定了目标服务的子集为 "v2"。
      weight: 25      // 为这个目标分配了 25% 的权重,意味着约 25% 的请求将被路由到这个目标服务。
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v1
      headers:
        response:
          remove:    // 用于移除响应头。
          - foo      // 移除了一个名为 "foo" 的响应头。
      weight: 75     // 为这个目标分配了75%的权重,意味着约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

在向调用方返回响应之前应用的 header 操作规则

 No
posted @ 2023-12-12 09:53  左扬  阅读(48)  评论(0编辑  收藏  举报
levels of contents