Service Istio

Istio官方

Istio

Istio / Traffic Management    CRD数据结构定义

Istio功能简介

Istio 服务治理流程

在控制面运行如下流程:

  1. 管理员通过命令行或者API创建流量规则,在Control Plane。
  2. Mixer,Citadel,Gelley,Pilot组件生成对应的CRD(Custom Resource Defintion)规则文件。
  3. Pilot 将服务治理(负载均衡、流量拆分、故障注入、熔断器)规则转换为Envoy的标准格式。
  4. Pilot将规则下发给对应Envoy节点,至此完成服务治理策略下发。

核心CRD (Custom Resource Definition) 

Istio 服务治理配置文件编写依赖于CRD,针对流量层面主要核心CRD列表与数据结构如下:

核心流量CRD

业务业务概念概念

说明说明

ServiceEntry

服务

定义mesh中的一个服务,包括服务发现、通信协议等。

Sidecar

服务拓扑(可见性)

定义每个服务可以访问的下游拓扑, ingress, egress。

VirtualService

路由配置

定义从上游到下游服务的流量路由规则。

DestinationRule

通信策略

定义访问下游服务的通信策略,包括连接、熔断、负载均衡等策略,subset管理。

通过kubectl进行CRD操作

下载附件配置:

# VirtualService.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: test2-virual-service
  namespace: default
spec:
  hosts:
  - group.test2
  tcp:
  - match:
    - sourceLabels:
        app: test1 //标记上游模块(注意不是bns)
    route:
    - destination:
        host: group.test2 //下游bns以及对应的访问配置
        subset: upstream1


# Sidecar.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Sidecar
metadata:
  name: test1-sidecar
  namespace: default
spec:
  workloadSelector:
    labels:
      app: //标记模块(注意不是bns)
  egress:
  - hosts:
    - "*/group.test2"
    port:
      number: 3307
      protocol: baidu_proxy
      name: BaiduProxy
    captureMode: NONE
    bind: 127.1.0.3
  - hosts:
    - "*/group.test3"
    port:
      number: 3308
      protocol: baidu_proxy
      name: BaiduProxy
    captureMode: NONE
    bind: 127.1.0.4


# ServiceEntry3.yaml
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: test3-serviec-entry
  namespace: default
spec:
  hosts:
  - group.test3
  location: MESH_EXTERNAL
  ports:
  - number: 3308
    name: BaiduProxy
    protocol: baidu_proxy
  resolution: DNS


# ServiceEntry2.yaml
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: test2-serviec-entry
  namespace: default
spec:
  hosts:
  - group.test2
  location: MESH_EXTERNAL
  ports:
  - number: 3307
    name: BaiduProxy
    protocol: baidu_proxy
  resolution: DNS


#  ServiceEntry1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: test1-serviec-entry
  namespace: default
spec:
  hosts:
  - group.test1
  location: MESH_EXTERNAL
  ports:
  - number: 3305
    name: BaiduProxy
    protocol: baidu_proxy
  resolution: DNS


# DestinationRule2.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: test3-destination-rule
  namespace: default
spec:
  host: group.test3
  trafficPolicy:
    loadBalancer:
      simple: LEAST_CONN
    connectionPool:
      tcp:
        maxConnections: 100
        connectTimeout: 30ms
        tcpKeepalive:
          time: 7200s
          interval: 75s


# DestinationRule1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: test2-destination-rule
  namespace: default
spec:
  host: group.test2
  trafficPolicy:
    loadBalancer:
      simple: LEAST_CONN
    connectionPool:
      tcp:
        maxConnections: 100
        connectTimeout: 30ms
        tcpKeepalive:
          time: 7200s
          interval: 75s
  subsets:
  - name: upstream1
    trafficPolicy:
      loadBalancer:
        simple: ROUND_ROBIN
      connectionPool:
        tcp:
          maxConnections: 1000
          connectTimeout: 60ms
          tcpKeepalive:
            time: 1200s
            interval: 75s
  - name: upstream2
    trafficPolicy:
      loadBalancer:
        simple: ROUND_ROBIN
      connectionPool:
        tcp:
          maxConnections: 500
          connectTimeout: 160ms
          tcpKeepalive:
            time: 1300s
            interval: 75s

安装ServiceEntry

// 载入ServiceEntry配置

kubectl create -f ServiceEntry1.yaml

kubectl create -f ServiceEntry2.yaml

kubectl create -f ServiceEntry3.yaml

// 查看载入结果

kubectl get ServiceEntry

安装Sidecar

kubectl create -f Sidecar.yaml

  

kubectl get Sidecar

安装VirtualService

kubectl create -f VirtualService.yaml

  

kubectl get VirtualService

安装DestinationRule

kubectl create -f DestinationRule1.yaml

kubectl create -f DestinationRule2.yaml

  

kubectl get DestinationRule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值