Istio 流量管理核心资源 VirtualService(虚拟服务)/DestinationRule(目标规则)/ Gateway(网关)/ ServiceEntry(服务入口)

istio最重要的是数据平面有个组件叫sidecar,它里面是采用的envoy的代理转发器,拦截所有业务程序的流量,只要你的业务程序接入了istio,到你业务的流量会被proxy接管,最重要的就是管理流量。

Istio流量管理核心资源


核心资源:

  • VirtualService(虚拟服务)
  • DestinationRule(目标规则)
  • Gateway(网关)
  • ServiceEntry(服务入口)

上面4个是lstio在流量管理实现的具体资源。也即是我们要实现流量管理策略,都是基于这些资源去配置的。

VirtualService


VirtualService(虚拟服务):

  • 定义路由规则
  • 描述满足条件的请求去哪里

这里创建了gateway,监听的地址是80,只创建监听的路口是不行的,不具备一个转发的功能,下面是其具体的路由规则,service名称和端口。

虚拟服务需要定义你关联的service和端口。

虚拟服务是绑定在gateway上面的。

[root@master httpbin]# cat httpbin-gateway.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: httpbin-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: httpbin
spec:
  hosts:
  - "*"
  gateways:
  - httpbin-gateway
  http:
  - route:
    - destination:
        host: httpbin      # 指定Service名称
        port:
          number: 8000     # service端口

 查看已创建的虚拟服务

[root@master httpbin]# kubectl get vs
NAME      GATEWAYS            HOSTS   AGE
httpbin   [httpbin-gateway]   [*]     12h

这是非常关键的一个资源,在istio当中暴露任何的服务,都要创建这个资源。

DestinationRule


DestinationRule(目标规则):定义虚拟服务路由目标地址的真实地址,即子集(subset),支持多种负载均衡策略:

  • 随机
  • 权重
  • 最小请求数

和virtualservice配合去使用的,可以将目标pod分为几组,然后好让virtual service转发到不同的组里面,类似于实现了灰度发布,同时它还支持多种的负载均衡策略。

subset里面可以有多组的目标服务,根据pod的标签去筛选然后关联。

如果通过virtualservice去绑定destinationrule就可以实现对后端的多组pod做流量方面的控制。

Gateway


Gateway(网关):为网格内服务对外访问入口,管理进出网格的流量,根据流入流出方向分为:

  • IngressGateway:接收外部访问,并将流量转发到网格内的服务。
  • EgressGateway:网格内服务访问外部应用。

猜你喜欢

转载自blog.csdn.net/qq_34556414/article/details/125755765