Istio 9 http流量控制

Submitted by Lizhe on Tue, 06/23/2020 - 02:14

在Kubernetes中访问一个服务时,需要指定协议,服务名和端口

在Istio的服务网格中对服务进行了进一步抽象

  • 可以使用Pod标签对具体服务进行分组
  • 可以定义负载均衡策略
  • 可以指定TLS要求
  • 可以为服务设置连接池大小

 

 

TrafficPolicy 

Name Description
ROUND_ROBIN
Round Robin policy. Default
LEAST_CONN
The least request load balancer uses an O(1) algorithm which selectstwo random healthy hosts and picks the host which has fewer activerequests.
RANDOM
The random load balancer selects a random healthy host. The randomload balancer generally performs better than round robin if no healthchecking policy is configured.
PASSTHROUGH
This option will forward the connection to the original IP addressrequested by the caller without doing any form of loadbalancing. This option must be used with care. It is meant foradvanced use cases. Refer to Original Destination load balancer inEnvoy for further details.

 

意思是请求将被传递给当前拥有最少活跃连接的server,同时考虑权重weight的因素。

apiVersion: networking.istio.io/v1alpha3

kind: DestinationRule

metadata:

  name: flaskapp-desrule 

  namespace: lizhe 

spec: 

  host: flaskapp-service

  trafficPolicy:

    loadBalancer:

      simple: LEAST_CONN

  subsets:

  - name: v1 

    labels: 

      version: v1

  - name: v2

    labels: 

      version: v2

 

 

apiVersion: networking.istio.io/v1alpha3

kind: VirtualService

metadata:

  name: flaskapp-default-v2

  namespace: lizhe 

spec: 

  hosts:

  - flaskapp-service

  http:

  - route: 

    - destination: 

        host: flaskapp-service

        subset: v1

      weight: 10

    - destination: 

        host: flaskapp-service

        subset: v2

      weight: 90

 

 

20200623121208

20200623122651