<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 配置請求的路由規則 **注意:本書中的 Service Mesh 章節已不再維護,請轉到 [istio-handbook](https://jimmysong.io/istio-handbook) 中瀏覽。** 在上一節[安裝istio](istio-installation.md)中我們創建[BookInfo](https://istio.io/docs/samples/bookinfo.html)的示例,熟悉了Istio的基本功能,現在我們再來看一下istio的高級特性——配置請求的路由規則。 使用istio我們可以根據**權重**和**HTTP headers**來動態配置請求路由。 ## 基于內容的路由 因為BookInfo示例部署了3個版本的評論微服務,我們需要設置一個默認路由。 否則,當你多次訪問應用程序時,會注意到有時輸出包含星級,有時候又沒有。 這是因為沒有明確的默認版本集,Istio將以隨機方式將請求路由到服務的所有可用版本。 **注意**:假定您尚未設置任何路由。如果您已經為示例創建了沖突的路由規則,則需要在以下命令中使用replace而不是create。 下面這個例子能夠根據網站的不同登陸用戶,將流量劃分到服務的不同版本和實例。跟kubernetes中的應用一樣,所有的路由規則都是通過聲明式的yaml配置。關于`reviews:v1`和`reviews:v2`的唯一區別是,v1沒有調用評分服務,productpage頁面上不會顯示評分星標。 1. 將微服務的默認版本設置成v1。 ```bash istioctl create -f samples/apps/bookinfo/route-rule-all-v1.yaml ``` 使用以下命令查看定義的路由規則。 ```bash istioctl get route-rules -o yaml ``` ```yaml type: route-rule name: details-default namespace: default spec: destination: details.default.svc.cluster.local precedence: 1 route: - tags: version: v1 --- type: route-rule name: productpage-default namespace: default spec: destination: productpage.default.svc.cluster.local precedence: 1 route: - tags: version: v1 --- type: route-rule name: reviews-default namespace: default spec: destination: reviews.default.svc.cluster.local precedence: 1 route: - tags: version: v1 --- type: route-rule name: ratings-default namespace: default spec: destination: ratings.default.svc.cluster.local precedence: 1 route: - tags: version: v1 --- ``` 由于對代理的規則傳播是異步的,因此在嘗試訪問應用程序之前,需要等待幾秒鐘才能將規則傳播到所有pod。 2. 在瀏覽器中打開BookInfo URL(`http://$GATEWAY_URL/productpage` ,我們在上一節中使用的是 `http://ingress.istio.io/productpage`)您應該會看到BookInfo應用程序的產品頁面顯示。 注意,產品頁面上沒有評分星,因為`reviews:v1`不訪問評級服務。 3. 將特定用戶路由到`reviews:v2`。 為測試用戶jason啟用評分服務,將productpage的流量路由到`reviews:v2`實例上。 ```bash istioctl create -f samples/apps/bookinfo/route-rule-reviews-test-v2.yaml ``` 確認規則生效: ```bash istioctl get route-rule reviews-test-v2 ``` ```yaml destination: reviews.default.svc.cluster.local match: httpHeaders: cookie: regex: ^(.*?;)?(user=jason)(;.*)?$ precedence: 2 route: - tags: version: v2 ``` 4. 使用jason用戶登陸productpage頁面。 你可以看到每個刷新頁面時,頁面上都有一個1到5顆星的評級。如果你使用其他用戶登陸的話,將因繼續使用`reviews:v1`而看不到星標評分。 ## 內部實現 在這個例子中,一開始使用istio將100%的流量發送到BookInfo服務的`reviews:v1`的實例上。然后又根據請求的header(例如用戶的cookie)將流量選擇性的發送到`reviews:v2`實例上。 驗證了v2實例的功能后,就可以將全部用戶的流量發送到v2實例上,或者逐步的遷移流量,如10%、20%直到100%。 如果你看了[故障注入](https://istio.io/docs/tasks/fault-injection.html)這一節,你會發現v2版本中有個bug,而在v3版本中修復了,你想將流量遷移到`reviews:v1`遷移到`reviews:v3`版本上,只需要運行如下命令: 1. 將50%的流量從`reviews:v1`轉移到`reviews:v3`上。 ```bash istioctl replace -f samples/apps/bookinfo/route-rule-reviews-50-v3.yaml ``` 注意這次使用的是`replace`命令,而不是`create`,因為該rule已經在前面創建過了。 2. 登出jason用戶,或者刪除測試規則,可以看到新的規則已經生效。 刪除測試規則。 ```bash istioctl delete route-rule reviews-test-v2 istioctl delete route-rule ratings-test-delay ``` 現在的規則就是刷新`productpage`頁面,50%的概率看到紅色星標的評論,50%的概率看不到星標。 注意:因為使用Envoy sidecar的實現,你需要刷新頁面很多次才能看到接近規則配置的概率分布,你可以將v3的概率修改為90%,這樣刷新頁面時,看到紅色星標的概率更高。 3. 當v3版本的微服務穩定以后,就可以將100%的流量分攤到`reviews:v3`上了。 ```bash istioctl replace -f samples/apps/bookinfo/route-rule-reviews-v3.yaml ``` 現在不論你使用什么用戶登陸`productpage`頁面,你都可以看到帶紅色星標評分的評論了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看