0
点赞
收藏
分享

微信扫一扫

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


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


Istio流量管理核心资源

核心资源:


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

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


VirtualService

VirtualService(虚拟服务):


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

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

这里创建了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转发到不同的组里面,类似于实现了灰度发布,同时它还支持多种的负载均衡策略。

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

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

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


Gateway

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


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

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

Gateway(网关)与Kubernetes Ingress有什么区别?


Kubernetes Ingress与Getaway都是用于为集群内服务提供访问入口, 但Ingress主要功能比较单一,不易于Istio现有流量管理功能集成。


目前Gateway支持的功能:


  • 支持L4-L7的负载均衡(很多只支持7层)
    支持HTTPS(客户端只需要去验证一下服务端证书是不是可信任就行了)和mTLS(mTLS支持双向的加密)
  • 支持流量镜像(流量复制)、熔断等

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

这里有个selector,类似于标签选择器,要将规则创建在哪个gateway上面。之后就是配置入口接受这个流量。

这个流量可以进来,接受了,要定义发给谁就需要virtualservice。virtualservice关联的是service。


 


ServiceEntry

ServiceEntry(服务入口):将网格外部服务添加到网格内,像网格内其他服务一样管理。


用的不是很多, 



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


举报

相关推荐

0 条评论