Istio官方
Istio / Traffic Management CRD数据结构定义
Istio功能简介
Istio 服务治理流程
在控制面运行如下流程:
- 管理员通过命令行或者API创建流量规则,在Control Plane。
- Mixer,Citadel,Gelley,Pilot组件生成对应的CRD(Custom Resource Defintion)规则文件。
- Pilot 将服务治理(负载均衡、流量拆分、故障注入、熔断器)规则转换为Envoy的标准格式。
- 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
|
安装Sidecar
|
安装VirtualService
|
安装DestinationRule
|