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

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

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

  Describes the delegate VirtualService. The following routing rules forward the traffic to /productpage by a delegate VirtualService named productpage, forward the traffic to /reviews by a delegate VirtualService named reviews.

描述了代理 VirtualService。以下路由规则将流量转发到 /productpage,由名为 productpage 的代理 VirtualService 完成,将流量转发到 /reviews,由名为 reviews 的代理 VirtualService 完成。

apiVersion: networking.istio.io/v1alpha3   //指定了Istio API 的版本,v1alpha3 是 Istio 网络 API 的一个版本。
kind: VirtualService    //指定了 kubernetes 资源的种类,这里是 virtualservice。
metadata:
  name: bookinfo        //指定了资源的名称,这里是 bookinfo。
  namespace: nsA        //指定了资源的命名空间,这里是 nsA。
spec:
  hosts:                //指定了虚拟服务的 host。
  - "bookinfo.com"      //指定了host名称为:bookinfo.com
  gateways:             //指定了这个 VirtualService 关联的网关。
  - mygateway           //指定了一个名为 mygateway 的网关。
  http:
  - match:              //定义了匹配条件
    - uri:              //指定了URI匹配条件
        prefix: "/productpage"  //指定了URI的前缀匹配条件,只有 URI 以 "/productpage" 开头的请求才会匹配这个规则。
    delegate:           //定义了匹配成功后要代理到的目标服务。
       name: productpage    //指定了目标服务的名称,这里是 "productpage"。
       namespace: nsA   //指定了目标服务所在的命名空间,这里是 "nsA"。
  - match:
    - uri:
        prefix: "/reviews"
    delegate:
        name: reviews
        namespace: nsB

我的理解是: VirtualService 配置定义了两个HTTP路由规则。第一个规则将路径前缀为“/productpage”的请求代理到在命名空间“nsA”中的“productpage”服务。第二个规则将路径前缀为“/reviews”的请求代理到在命名空间“nsB”中的“reviews”服务。通过这种方式,Istio可以根据请求的URI将请求智能地路由到正确的服务,从而实现服务的解耦和灵活路由。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: productpage
  namespace: nsA
spec:
  http:
  - match:
     - uri:
        prefix: "/productpage/v1/"
    route:
    - destination:
        host: productpage-v1.nsA.svc.cluster.local
  - route:
    - destination:
        host: productpage.nsA.svc.cluster.local

我的理解是: VirtualService 配置定义了两个 HTTP 路由规则。第一个规则将路径前缀为 "/productpage/v1/" 的请求路由到名为 "productpage-v1" 的服务(在 "nsA" 命名空间中)。第二个规则没有定义匹配条件,所以它会作为一个默认路由规则,将所有其他未匹配的请求路由到名为 "productpage" 的服务(也在 "nsA" 命名空间中)。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
  namespace: nsB
spec:
  http:
  - route:
    - destination:
        host: reviews.nsB.svc.cluster.local

我的理解是: 定义 Istio 虚拟服务的 YAML 配置文件。它指定了虚拟服务的名称为 reviews,所在的命名空间为 nsB,并定义了一个 HTTP 路由规则,将流量路由到名为 reviews.nsB.svc.cluster.local 的后端服务。

Field

Type

Description Required
name string

Name specifies the name of the delegate VirtualService.

name 指定代理 VirtualService 的名称。

No
namespace string

Namespace specifies the namespace where the delegate VirtualService resides. By default, it is same to the root’s.

命名空间指定代理 VirtualService 所在的命名空间。默认情况下,它与 root 的命名空间相同。

No
posted @ 2023-12-11 16:54  左扬  阅读(66)  评论(0编辑  收藏  举报
levels of contents