[Day23]Virtual Service

上一篇的Bookinfo这个服务中,我们有使用samples/bookinfo/networking/bookinfo-gateway.yaml进行部署。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo
spec:
  hosts:
  - "*" 
  gateways:
  - bookinfo-gateway
  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

hosts

hosts可以使用多组host name,主要是针对要导入VirtualService的host,需要设定在这边,像下图的例子,当host name为下面例子时才会导流进来。
VirtualService可以为IP或是DNS

hosts:
  - "www.imtest.com" 
  - "www.imtest.net"

路由规则

这边使用了http是这区域定义了路由规则,match表示要符合规则的才会导入到对应的服务。

  • exact: /productpage : 绝对路径
  • prefix: /static : 前缀static的路径
  • regex : 使用正则式
    除了uri,外还可以使用headers来判断。
    route : 当符合match的路由条件时,VirtualService就会把流量导到host的服务
http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        prefix: /static
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    - headers: ## header里面有end-user=jason
        end-user:
          exact: jason
    route:
    - destination:
        host: productpage
        port:
          number: 9080      

也可以写成一个VirtualService 多组路由规则,下面的路由规则设定了从bookinfo-gateway进来流量,透过不同的path导至不同的服务的需求。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo
spec:
  hosts:
  - "*" 
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - uri:
        exact: /productpage1    
    route:
    - destination:
        host: productpage
        port:
          number: 9080
    name: "route1"
  - match:    
    - uri:
        prefix: /static   
    route:
    - destination:
        host: productpage
        port:
          number: 9080
    name: "route2"
  - match:    
    - uri:
        prefix: /test2   
    route:
    - destination:
        host: productpage2
        port:
          number: 9080
    name: "route3"

以上是上面case中会用到的用法,如果需要更多的用法可以参考官网的文件喔/images/emoticon/emoticon01.gif
官方virtual-service


<<:  [DAY 16]用bot打出色色柴犬counter牌

>>:  [Day30] Tableau 轻松学 - 总结

D29. 学习基础C、C++语言

D29. C++字串 C++ string的特别用法 str.size():字串长度。 str.em...

Re: 新手让网页 act 起来: Day08 - 简单却不是很容易懂的 key (1)

key 是 React element 中的一个属性,相信很多人在撰写 React 的时候都会遇到下...

服务器安装libsodium支持chacha20&salsa20

使用 salsa20 或 chacha20 或 chacha20-ietf 算法,需要安装 libs...

[Day 27] 微探讨 Pure pipe 与 Impure pipe

今天要介绍的 Tip 是有关於 pipe 的 pure 与 impure,当没有任何额外的设定下,自...

Day8 用python写UI-聊聊功能钮Button

Button()方法有在前两天的时候提了一些,今天会更详细的介绍Buton()的使用方法 (o゜▽゜...