• istio系列:第五章-ServiceEntry内到外的通讯配置


    istio系列:第五章-ServiceEntry内到外的通讯配置

    在isito中,我们一般都是通过服务名去注册中心寻找服务,原理类似于springcloud中的nacos。对于服务注册一般都是采用自动发现与注册的方式,但是istio提供了ServiceEntry资源让我们可以手动对服务进行注册。

    在这里我们想到了一个问题就是那可不可以将外部服务也注册到istio中去哪?答案是可以。

    接下来就让我们了解一下ServiceEntry的各个属性

    type ServiceEntry struct {
       Hosts []string
       Addresses []string 
       Ports []*Port
       Location ServiceEntry_Location 
       Resolution ServiceEntry_Resolution 
       Endpoints []*WorkloadEntry 
       WorkloadSelector *WorkloadSelector 
       ExportTo []string 
       SubjectAltNames []string 
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    Hosts

    定义服务名称,可以是DNS、前缀模糊匹配,用于virtual service中的host等使用

    Addresses

    表示与服务关联的虚拟IP地址,可以是CIDR这种前缀表达式。对于HTTP的流量,该字段被忽略,可以通过该IP地址访问该服务

    Ports

    与外部服务关联的端口

    
    type Port struct {
      // 监听端口
       Number uint32 
      // 适应协议
       Protocol string 
      // 端口名称
       Name string 
      // 流量所在端点的端口号
       TargetPort uint32 
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    Location

    指定服务是否应被视为网格外部,标识服务属于外部服务还是内部服务。如果是外部服务mTls双向认证会被禁用

    const (
      // 外部服务
       ServiceEntry_MESH_EXTERNAL ServiceEntry_Location = 0
      // 内部服务
       ServiceEntry_MESH_INTERNAL ServiceEntry_Location = 1
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    Resolution

    服务发现的模式,用来设置代理解析服务的方式,将一个服务名解析到一个后端IP地址上

    const (
       // 用于当连接的目标地址已经是一个明确 IP 的场景
       ServiceEntry_NONE ServiceEntry_Resolution = 0
       // 用在已经用endpoints设置了服务实例的地址场景中,即不用解析。
       ServiceEntry_STATIC ServiceEntry_Resolution = 1
       // 用查询环境中的DNS进行解析
       ServiceEntry_DNS ServiceEntry_Resolution = 2
       ServiceEntry_DNS_ROUND_ROBIN ServiceEntry_Resolution = 3
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    Endpoints

    配置目的地址的IP、端口号等信息

    type WorkloadEntry struct {
       Address string 
       Ports map[string]uint32 
       Labels map[string]string 
       Network string 
       Locality string 
       Weight uint32 
       ServiceAccount string 
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    Address

    必选字段,表示网络后端的地址。在前面 ServiceEntry 的解析方式中resolution 被设置为DNS时,address可以使用域名,但要求是明确的地址,不可以使用模糊匹配。

    Ports

    端口列表

    Labels

    后端的标签

    Network

    高级配置主要用在Istio多集群中。所有属于相同network的后端都可以直接互访,不在同一个 network 的后端不能直接访问。在使用 Istio Gateway时可以对不同network的后端建立连接

    Locality

    后端的locality,主要用于亲和性路由。即Envoy可以基于这个标识做本地化路由,优先路由到本地的后端上。locality表示一个故障域,常见的如国家、地区、区域,也可以分割每个故障域来表
    示任意层次的结构

    Weight

    负载均衡的权重,权重越高,接收的流量占比越大。

    WorkloadSelector

    过滤工作负载,仅适用于内网服务。

    ExportTo

    命名空间的限制,如果没有配置则对所有的命名空间都有效

    SubjectAltNames

    表示这个服务负载的SAN列表

  • 相关阅读:
    Kotlin学习之2
    UE 5.1正式发布,有哪些值得一试的新功能?
    这 20 道 Redis 经典面试题你还不会,就别去面试了!
    反诈中心拦截网站域名措施与申诉方法
    unicodedata.normalize ——Unicode字符串标准化
    字符型液晶显示器LCD 1602的显示控制(Keil+Proteus)
    电动车展示预约小程序的作用如何
    下班前几分钟,Express 快速入门
    【BOOST C++ 11 时钟数据】(1)计时码表(11-13)
    10KM无人机高清图传通信模组,低延迟、抗干扰,飞睿智能无线MESH组网模块
  • 原文地址:https://blog.csdn.net/a1023934860/article/details/125441209