AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當前位置:首頁 > 科技  > 軟件

Istio流量管理之請求路由分析

來源: 責編: 時間:2023-11-09 09:15:13 333觀看
導讀前面我們了解了 Gateway 和 VirtualService 資源對象的作用,以及它們是如何影響 Envoy 的配置的,那么這些資源對象又是如何影響流量的呢?通過 Istio 如何實現流量管理的呢?流量管理概述Istio 的流量路由規則可以很容易的

XKB28資訊網——每日最新資訊28at.com

前面我們了解了 Gateway 和 VirtualService 資源對象的作用,以及它們是如何影響 Envoy 的配置的,那么這些資源對象又是如何影響流量的呢?通過 Istio 如何實現流量管理的呢?XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

流量管理概述

Istio 的流量路由規則可以很容易的控制服務之間的流量和 API 調用。Istio 簡化了服務級別屬性的配置,比如熔斷器、超時和重試,并且能輕松的設置重要的任務,如 A/B 測試、金絲雀發布、基于流量百分比切分的分階段發布等。它還提供了開箱即用的故障恢復特性, 有助于增強應用的健壯性,從而更好地應對被依賴的服務或網絡發生故障的情況。XKB28資訊網——每日最新資訊28at.com

為了在網格中路由,Istio 需要知道所有的 endpoint 在哪以及它們屬于哪些服務。為了定位到 service registry(服務注冊中心),Istio 會連接到一個服務發現系統。如果在 Kubernetes 集群上安裝了 Istio,那么它將自動檢測該集群中的服務和 endpoint。XKB28資訊網——每日最新資訊28at.com

請求路由

首先我們來實現下最基本的流量請求路由的功能,這里我們將學習如何將請求動態路由到微服務的多個版本。XKB28資訊網——每日最新資訊28at.com

我們知道 Bookinfo 示例包含四個獨立的微服務,每個微服務都有多個版本。其中 reviews 服務的三個不同版本已經部署并同時運行。我們可以在瀏覽器中訪問 Bookinfo 應用程序并刷新幾次。正常會看到三種不同的 reviews 服務版本的輸出,有時書評的輸出包含星級評分,有時則不包含。這是因為沒有明確的默認服務版本可路由,Istio 將以循環方式將請求路由到所有可用版本。XKB28資訊網——每日最新資訊28at.com

我們首先來將所有流量路由到微服務的 v1 版本,稍后,您將應用規則根據 HTTP 請求 header 的值路由流量。XKB28資訊網——每日最新資訊28at.com

路由到指定版本

要只路由到一個版本,則需要為微服務設置默認版本的 VirtualService。XKB28資訊網——每日最新資訊28at.com

應用規則

Istio 使用 VirtualService 來定義路由規則,只需要應用下面的資源對象即可:XKB28資訊網——每日最新資訊28at.com

$ kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yamlvirtualserviceworking.istio.io/productpage createdvirtualserviceworking.istio.io/reviews createdvirtualserviceworking.istio.io/ratings createdvirtualserviceworking.istio.io/details created

該資源清單中定義了四個 VirtualService 對象,分別是 productpage、reviews、ratings、details,它們分別對應著 Bookinfo 應用中的四個微服務,完整的清單如下所示:XKB28資訊網——每日最新資訊28at.com

# virtual-service-all-v1.yamlapiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: productpagespec:  hosts:    - productpage  http:    - route:        - destination:            host: productpage            subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: reviewsspec:  hosts:    - reviews  http:    - route:        - destination:            host: reviews            subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: ratingsspec:  hosts:    - ratings  http:    - route:        - destination:            host: ratings            subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: detailsspec:  hosts:    - details  http:    - route:        - destination:            host: details            subset: v1---

我們可以看到這里的 VirtualService 對象中都定義了 subset 字段,這個字段就是用來指定微服務的版本的,這里我們將所有的微服務都指定為 v1 版本,這樣所有的流量都會被路由到 v1 版本的微服務中,包括 reviews 服務,這樣我們就不會再看到星級評分了。XKB28資訊網——每日最新資訊28at.com

但是如果我們現在直接去訪問 Bookinfo 應用的話,是不能正常訪問的,因為我們壓根就還沒指定這些 v1 版本的微服務到底在哪里。XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

bookinfo errorXKB28資訊網——每日最新資訊28at.com

這個時候就需要用到另外一個資源對象 DestinationRule 了,我們需要為每個微服務創建一個 DestinationRule 對象,用來指定這些微服務的實際地址,這樣 VirtualService 對象才能將流量路由到這些微服務中。Istio 在 DestinationRule 目標規則中使用 subsets 定義服務的版本,運行以下命令為 Bookinfo 服務創建默認的目標規則即可:XKB28資訊網——每日最新資訊28at.com

$ kubectl apply -f samples/bookinfo/networking/destination-rule-all.yamldestinationruleworking.istio.io/productpage createddestinationruleworking.istio.io/reviews createddestinationruleworking.istio.io/ratings createddestinationruleworking.istio.io/details created

該資源清單中定義了四個 DestinationRule 對象,分別是 productpage、reviews、ratings、details 幾個服務的目標規則,它們分別對應著 Bookinfo 應用中的四個微服務,完整的清單如下所示:XKB28資訊網——每日最新資訊28at.com

# destination-rule-all.yamlapiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata:  name: productpagespec:  host: productpage  subsets:    - name: v1      labels:        version: v1---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata:  name: reviewsspec:  host: reviews  subsets:    - name: v1      labels:        version: v1    - name: v2      labels:        version: v2    - name: v3      labels:        version: v3---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata:  name: ratingsspec:  host: ratings  subsets:    - name: v1      labels:        version: v1    - name: v2      labels:        version: v2    - name: v2-mysql      labels:        version: v2-mysql    - name: v2-mysql-vm      labels:        version: v2-mysql-vm---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata:  name: detailsspec:  host: details  subsets:    - name: v1      labels:        version: v1    - name: v2      labels:        version: v2---

現在我們就可以正常訪問 Bookinfo 應用了,并且無論刷新多少次,頁面的評論部分都不會顯示評級星標,這是因為我們將 Istio 配置為將 reviews 服務的所有流量路由到版本 reviews:v1,而此版本的服務不訪問星級評分服務。XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

v1版本reviewXKB28資訊網——每日最新資訊28at.com

這樣我們就成功將流量路由到服務的某一個版本上了。XKB28資訊網——每日最新資訊28at.com

原理分析

前面章節中我們只定義了一個名為 bookinfo 的 VirtualService 資源對象就可以正常訪問了:XKB28資訊網——每日最新資訊28at.com

apiVersion: networking.istio.io/v1beta1kind: VirtualServicemetadata:  name: bookinfo  namespace: defaultspec:  gateways:    - bookinfo-gateway  hosts:    - "*"  http:    - match:        - uri:            exact: /productpage        - uri:            prefix: /static        - uri:            exact: /login        - uri:            exact: /logout        - uri:            prefix: /api/v1/products      route:        - destination:            host: productpage            port:              number: 9080

很明顯上面這個虛擬服務對象是我們訪問 Bookinfo 應用的入口路由規則,所以這個虛擬服務對象實際上是為 istio-ingressgateway 入口網關服務定義的。 它將所有的流量都路由到了 productpage 這個服務上,而 productpage 這個服務又會去調用其他的服務來獲取數據,在 productpage 服務中調用其他微服務 其實就是直接通過服務名稱來調用的,比如調用 reviews 服務就是直接通過 reviews:9080 這個服務來調用的,我們可以查看 productpage 的代碼來驗證這一點:XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

productpageXKB28資訊網——每日最新資訊28at.com

我們可以再次查看 Bookinfo 在網格內的請求架構圖:XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

BookInfo 架構XKB28資訊網——每日最新資訊28at.com

當我們在瀏覽器中訪問 http://<gateway url>/productpage 時,請求將進入網格中的 istio-ingressgateway 服務,然后將請求轉發到 productpage 服務。productpage 服務將調用 reviews 和 details 服務來填充頁面的內容,然后將其返回給用戶。(reviews 服務包括 3 個不同版本的應用,可以通過 version 標簽區分)XKB28資訊網——每日最新資訊28at.com

現在我們只想將流量路由到 reviews:v1 版本去,按照傳統的方法只需要將 reviews 的 Service 對象去強制關聯 version: v1 這個標簽即可,現在我們所有的服務都被注入了一個 Envoy 的 Sidecar 代理,通過 Envoy 很容易就可以實現這個路由功能,而相應的在 Istio 中我們只需要通過 VirtualService 和 DestinationRule 這兩個資源對象就可以來實現了。上面我們創建的關于 reviews 服務的這兩個對象如下所示:XKB28資訊網——每日最新資訊28at.com

apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: reviewsspec:  hosts:    - reviews  http:    - route:        - destination:            host: reviews            subset: v1---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata:  name: reviewsspec:  host: reviews  subsets:    - name: v1      labels:        version: v1    - name: v2      labels:        version: v2    - name: v3      labels:        version: v3

那么這兩個對象是如何來影響 Envoy Sidecar 的呢?前面我們已經分析了流量從 istio-ingressgateway 進來后被路由到了 productpage 服務,那么 productpage 又該如何去訪問其他微服務呢?同樣我們可以使用 istioctl proxy-config 來查看 productpage 服務的 Envoy 配置。XKB28資訊網——每日最新資訊28at.com

每個 Envoy Sidecar 都有一個綁定到 0.0.0.0:15001 的監聽器,然后利用 IP tables 將 pod 的所有入站和出站流量路由到這里,此監聽器會配置一個 useOriginalDst: true,這意味著它將請求交給最符合請求原始目標的監聽器。如果找不到任何匹配的虛擬監聽器,它會將請求發送給返回 404 的 BlackHoleCluster,我們可以查看下 15001 端口的監聽器配置:XKB28資訊網——每日最新資訊28at.com

$ istioctl proxy-config listeners productpage-v1-564d4686f-wwqqf --port 15001 -oyaml- address:    socketAddress:      address: 0.0.0.0      portValue: 15001  filterChains:  - filterChainMatch:      destinationPort: 15001    filters:    - name: istio.stats      typedConfig:        '@type': type.googleapis.com/stats.PluginConfig    - name: envoy.filterswork.tcp_proxy      typedConfig:        '@type': type.googleapis.com/envoy.extensions.filterswork.tcp_proxy.v3.TcpProxy        cluster: BlackHoleCluster        statPrefix: BlackHoleCluster    name: virtualOutbound-blackhole  - filters:    - name: istio.stats      typedConfig:        '@type': type.googleapis.com/stats.PluginConfig    - name: envoy.filterswork.tcp_proxy      typedConfig:        '@type': type.googleapis.com/envoy.extensions.filterswork.tcp_proxy.v3.TcpProxy        # ......        cluster: PassthroughCluster        statPrefix: PassthroughCluster    name: virtualOutbound-catchall-tcp  name: virtualOutbound  trafficDirection: OUTBOUND  useOriginalDst: true

實際上我們的請求是到 9080 端口(productpage 服務綁定 9080 端口)的 HTTP 出站請求,這意味著它被切換到 0.0.0.0:9080 虛擬監聽器。所以我們查看下 9080 端口的監聽器配置:XKB28資訊網——每日最新資訊28at.com

# productpage 默認訪問其他服務的 9080 端口$ istioctl proxy-config listeners productpage-v1-564d4686f-wwqqf --port 9080 -oyaml- address:    socketAddress:      address: 0.0.0.0      portValue: 9080  # ......        rds:          configSource:            ads: {}            initialFetchTimeout: 0s            resourceApiVersion: V3          routeConfigName: "9080"  # RDS的路由配置名稱  # ......  name: 0.0.0.0_9080  trafficDirection: OUTBOUND  # 出流量

可以看到此監聽器在其配置的 RDS 中查找名為 9080 的路由配置,我們可以使用 istioctl proxy-config routes 命令來查看這個路由配置的詳細信息:XKB28資訊網——每日最新資訊28at.com

# 查看 9080 這個路由配置$ istioctl proxy-config routes productpage-v1-564d4686f-wwqqf --name 9080 -oyaml- name: "9080"  virtualHosts:  - domains:    - details.default.svc.cluster.local    - details    - details.default.svc    - details.default    - 10.111.83.224    name: details.default.svc.cluster.local:9080    routes:    - decorator:        operation: details.default.svc.cluster.local:9080/*      match:        prefix: /      metadata:        filterMetadata:          istio:            config: /apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/details      route:        cluster: outbound|9080|v1|details.default.svc.cluster.local        # ......  - domains:    - productpage.default.svc.cluster.local    - productpage    - productpage.default.svc    - productpage.default    - 10.97.120.23    name: productpage.default.svc.cluster.local:9080    routes:    - decorator:        operation: productpage.default.svc.cluster.local:9080/*      match:        prefix: /      name: default      route:        cluster: outbound|9080||productpage.default.svc.cluster.local        # ......  - domains:    - ratings.default.svc.cluster.local    - ratings    - ratings.default.svc    - ratings.default    - 10.101.184.235    name: ratings.default.svc.cluster.local:9080    routes:    - decorator:        operation: ratings.default.svc.cluster.local:9080/*      match:        prefix: /      metadata:        filterMetadata:          istio:            config: /apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/ratings      route:        cluster: outbound|9080|v1|ratings.default.svc.cluster.local        # ......  - domains:    - reviews.default.svc.cluster.local    - reviews    - reviews.default.svc    - reviews.default    - 10.97.120.56    name: reviews.default.svc.cluster.local:9080    routes:    - decorator:        operation: reviews.default.svc.cluster.local:9080/*      match:        prefix: /      metadata:        filterMetadata:          istio:            config: /apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/reviews      route:        cluster: outbound|9080|v1|reviews.default.svc.cluster.local        # ......  - domains:    - '*'    name: allow_any    routes:    - match:        prefix: /      name: allow_any      route:        cluster: PassthroughCluster        # ......

這個路由配置中其實包含了 K8s Service 對象中監聽 9080 端口的所有服務,如果沒有創建對應的 VirtualService 對象,對應的路由配置就沒有 metadata.filterMetadata.istio.config 這個屬性。比如現在我們正在通過 productpage 請求前往 reviews 服務,因此 Envoy 將選擇我們的請求與域匹配的虛擬主機。一旦在域上匹配,Envoy 會查找與請求匹配的第一條路徑,我們這里沒有任何高級路由,因此只有一條路由匹配所有內容。這條路由告訴 Envoy 將請求發送到 outbound|9080|v1|reviews.default.svc.cluster.local 集群,因為前面我們創建的 reviews 這個 VirtualService 對象配置了的 destination.subset: v1,所以這里的集群命名上多了一個 subset。XKB28資訊網——每日最新資訊28at.com

需要注意的是我們在 VirtualService 對象里面配置了 destination.subset: v1,那么必須要有對應的 subset 存在才行,否則不會生成對應的 Envoy 集群配置,那么就不能正常訪問該服務了,而該 subset 就是通過前面的 DestinationRule 對象來定義的,現在我們就可以來查看這個集群配置了:XKB28資訊網——每日最新資訊28at.com

$ istioctl proxy-config cluster productpage-v1-564d4686f-wwqqf --fqdn reviews.default.svc.cluster.local -o yaml- edsClusterConfig:    edsConfig:      ads: {}      initialFetchTimeout: 0s      resourceApiVersion: V3    serviceName: outbound|9080||reviews.default.svc.cluster.local  lbPolicy: LEAST_REQUEST  metadata:    filterMetadata:      istio:        config: /apis/networking.istio.io/v1alpha3/namespaces/default/destination-rule/reviews        services:        - host: reviews.default.svc.cluster.local          name: reviews          namespace: default  # ......  name: outbound|9080||reviews.default.svc.cluster.local  type: EDS- edsClusterConfig:    edsConfig:      ads: {}      initialFetchTimeout: 0s      resourceApiVersion: V3    serviceName: outbound|9080|v1|reviews.default.svc.cluster.local  lbPolicy: LEAST_REQUEST  metadata:    filterMetadata:      istio:        config: /apis/networking.istio.io/v1alpha3/namespaces/default/destination-rule/reviews        services:        - host: reviews.default.svc.cluster.local          name: reviews          namespace: default        subset: v1  name: outbound|9080|v1|reviews.default.svc.cluster.local  # ......  type: EDS- edsClusterConfig:    edsConfig:      ads: {}      initialFetchTimeout: 0s      resourceApiVersion: V3    serviceName: outbound|9080|v2|reviews.default.svc.cluster.local  filters:  - name: istio.metadata_exchange    typedConfig:      '@type': type.googleapis.com/envoy.tcp.metadataexchange.config.MetadataExchange      protocol: istio-peer-exchange  lbPolicy: LEAST_REQUEST  metadata:    filterMetadata:      istio:        config: /apis/networking.istio.io/v1alpha3/namespaces/default/destination-rule/reviews        services:        - host: reviews.default.svc.cluster.local          name: reviews          namespace: default        subset: v2  name: outbound|9080|v2|reviews.default.svc.cluster.local  # ......  type: EDS- edsClusterConfig:    edsConfig:      ads: {}      initialFetchTimeout: 0s      resourceApiVersion: V3    serviceName: outbound|9080|v3|reviews.default.svc.cluster.local  filters:  - name: istio.metadata_exchange    typedConfig:      '@type': type.googleapis.com/envoy.tcp.metadataexchange.config.MetadataExchange      protocol: istio-peer-exchange  lbPolicy: LEAST_REQUEST  metadata:    filterMetadata:      istio:        config: /apis/networking.istio.io/v1alpha3/namespaces/default/destination-rule/reviews        services:        - host: reviews.default.svc.cluster.local          name: reviews          namespace: default        subset: v3  name: outbound|9080|v3|reviews.default.svc.cluster.local  # ......  type: EDS

從上面配置可以看到里面一共包含了 4 個 reviews 相關的集群,一個是原始的不包含 subset 的,而另外三個就是前面我們在 DestinationRule 對象中配置的 3 個 subset,所以其實 DestinationRule 映射到 Envoy 的配置文件中就是 Cluster。XKB28資訊網——每日最新資訊28at.com

最后我們同樣還可以查看每個集群下面包含的 endpoint 有哪些:XKB28資訊網——每日最新資訊28at.com

$ istioctl proxy-config endpoint productpage-v1-564d4686f-wwqqf --cluster "outbound|9080||reviews.default.svc.cluster.local" -o yaml- edsServiceName: outbound|9080||reviews.default.svc.cluster.local  - address:      socketAddress:        address: 10.244.2.84        portValue: 9080    # ......    weight: 1  - address:      socketAddress:        address: 10.244.2.83        portValue: 9080    # ......    weight: 1  - address:      socketAddress:        address: 10.244.2.88        portValue: 9080    # ......    weight: 1  name: outbound|9080||reviews.default.svc.cluster.local  observabilityName: outbound|9080||reviews.default.svc.cluster.local$ istioctl proxy-config endpoint productpage-v1-564d4686f-wwqqf --cluster "outbound|9080|v1|reviews.default.svc.cluster.local" -o yaml- edsServiceName: outbound|9080|v1|reviews.default.svc.cluster.local  hostStatuses:  - address:      socketAddress:        address: 10.244.2.84        portValue: 9080    weight: 1  name: outbound|9080|v1|reviews.default.svc.cluster.local  observabilityName: outbound|9080|v1|reviews.default.svc.cluster.local# 過濾 versinotallow=v1 的 reviews pod$ kubectl get pod -l app=reviews,versinotallow=v1 -o wideNAME                          READY   STATUS    RESTARTS        AGE     IP            NODE    NOMINATED NODE   READINESS GATESreviews-v1-86896b7648-zjh2n   2/2     Running   4 (5h18m ago)   6d17h   10.244.2.84   node2   <none>           <none>

可以看到不包含 subset 的集群下面的 endpoint 其實就是 reviews 這個 Service 對象的 endpoint 集合,包含 subset 就只有和該子集匹配的后端實例了。到了這一步,一切皆明了,后面的事情就跟之前的套路一樣了,具體的 Endpoint 對應打了標簽 versinotallow=v1 的 Pod。XKB28資訊網——每日最新資訊28at.com

到這里我們是不是就實現了通過 VirtualService 和 DestinationRule 對象將流量路由到了指定的版本上面了,上面的整個過程就是請求從 productpage 到 reviews 的過程,從 reviews 到網格內其他應用的流量與上面類似,就不展開討論了。XKB28資訊網——每日最新資訊28at.com

基于用戶身份的路由

接下來我們繼續更改路由配置,將來自特定用戶的所有流量路由到特定服務版本。我們這里將配置來自名為 Jason 的用戶的所有流量被路由到服務 reviews:v2。XKB28資訊網——每日最新資訊28at.com

注意 Istio 對用戶身份沒有任何特殊的內置機制,productpage 服務在所有到 reviews 服務的 HTTP 請求中都增加了一個自定義的 end-user 請求頭來實現該效果:headers['end-user'] = session['user']。XKB28資訊網——每日最新資訊28at.com

要實現該功能,只需要創建下面的資源對象即可:XKB28資訊網——每日最新資訊28at.com

$ kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yamlvirtualserviceworking.istio.io/reviews configured

該資源清單文件創建了一個如下所示的 VirtualService 資源對象:XKB28資訊網——每日最新資訊28at.com

# virtual-service-reviews-test-v2.yamlapiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: reviewsspec:  hosts:    - reviews  http:    - match:        - headers:            end-user:              exact: jason      route:        - destination:            host: reviews            subset: v2    - route:        - destination:            host: reviews            subset: v1

該對象設置了一條路由規則,它會根據 productpage 服務發起的請求的 end-user 自定義請求頭內容進行匹配,如果有該內容且為 jason 則會將流量路由到 reviews 服務的 v2 版本,其余的還是被路由到 v1 版本去。XKB28資訊網——每日最新資訊28at.com

現在我們可以前往瀏覽器訪問 Bookinfo 應用,多刷新幾次可以看到評論始終訪問到的是 v1 版本的服務,即沒有星標的:XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

BookinfoXKB28資訊網——每日最新資訊28at.com

然后我們點擊頁面右上角的 Sign in 按鈕,使用 jason 進行登錄,登錄后頁面就會出現帶有黑色星標的 v2 版本的評論服務,即使多刷新幾次依然如此:XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

Bookinfo jasonXKB28資訊網——每日最新資訊28at.com

如果我們選擇使用其他用戶進行登錄或者注銷則星標就會消失,這是因為除了 Jason 之外,所有用戶的流量都被路由到 reviews:v1。XKB28資訊網——每日最新資訊28at.com

同樣的我們可以去查看下對應的 Envoy Sidecar 配置的變化,因為這里我們只更新了一個 VirtualService 對象,所以只會對 Envoy 的路由表產生影響,查看對應的路由配置即可:XKB28資訊網——每日最新資訊28at.com

$ istioctl proxy-config routes productpage-v1-564d4686f-wwqqf --name 9080 -oyaml- name: "9080"  validateClusters: false  virtualHosts:  # ......  - domains:    - reviews.default.svc.cluster.local    - reviews    - reviews.default.svc    - reviews.default    - 10.97.120.56    includeRequestAttemptCount: true    name: reviews.default.svc.cluster.local:9080    routes:    - decorator:        operation: reviews.default.svc.cluster.local:9080/*      match:        caseSensitive: true        headers:        - name: end-user          stringMatch:            exact: jason        prefix: /      metadata:        filterMetadata:          istio:            config: /apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/reviews      route:        cluster: outbound|9080|v2|reviews.default.svc.cluster.local        maxGrpcTimeout: 0s        # ......    - decorator:        operation: reviews.default.svc.cluster.local:9080/*      match:        prefix: /      metadata:        filterMetadata:          istio:            config: /apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/reviews      route:        cluster: outbound|9080|v1|reviews.default.svc.cluster.local        maxGrpcTimeout: 0s        # ......

從配置上我們可以看到現在的 Envoy 配置中新增了一條路由規則,如下所示:XKB28資訊網——每日最新資訊28at.com

match:  caseSensitive: true  headers:    - name: end-user      stringMatch:        exact: jason  prefix: /route:  cluster: outbound|9080|v2|reviews.default.svc.cluster.local

當請求頭中包含 end-user:jason 的時候請求會被路由到 outbound|9080|v2|reviews.default.svc.cluster.local 這個 Envoy Cluster 集群,這個集群就是前面我們通過 DestinationRule 創建的 v2 這個子集,所以最后請求會被路由到帶有黑色星標的評論服務去。XKB28資訊網——每日最新資訊28at.com

XKB28資訊網——每日最新資訊28at.com

Kiali DashboardXKB28資訊網——每日最新資訊28at.com

到這里我們就明白了要通過 Istio 實現服務的流量管理,需要用到 Gateway、VirtualService、DestinationRule 三個 CRD 對象,這些對象其實最終都是去拼湊 Envoy 的配置,每個對象管理 Envoy 配置的一部分,把這個關系搞清楚我們就能更好的掌握 Istio 的使用了。XKB28資訊網——每日最新資訊28at.com

本文鏈接:http://www.tebozhan.com/showinfo-26-17904-0.htmlIstio流量管理之請求路由分析

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: Spring Cache 緩存注解這樣用,實在是太香了!

下一篇: 使用 CSS Grid 的響應式網頁設計:消除媒體查詢過載

標簽:
  • 熱門焦點
Top