Istio流量管理补充
目录:
流量管理类型
流量管理类型有6种
Sidecar
Sidecar是描述sidecar代理的配置,在默认情况下,每个Envoy代理都可以访问来自和它关联的workload的所有端口请求,然后转发,Sidecar配置可以对Envoy做配置
- 调整Envoy代理接受的端口和协议
- 限制Envoy可以访问的服务
- VirtualService
- DestinationRule
- ServiceEntry
- Gateway
- Sidecar
- EnvoyFilter Sidecar不配置workloadSelector可以应用于namespace中,也可以指定workloadSelector应用于特定的workload,每个namespace只能有一个不配置workloadSelector的Sidecar配置
下面的配置配置了namespace为全局默认配置istio-config,会应用到所有的namespace的sidecar
apiVersion: networking.istio.io/v1alpha3
kind: Sidecar
metadata:
name: default
namespace: `istio-config`
spec:
egress:
- hosts:
- "./*"
- "istio-system/*"
功能是仅允许将流量发送到本namespace和istio-system namespace中的workload
下面配置是在prod-us1的namespace覆盖全局默认定义,流量只能到prod-us1、prod-apis和istio-system三个namespace
apiVersion: networking.istio.io/v1alpha3
kind: Sidecar
metadata:
name: default
namespace: prod-us1
spec:
egress:
- hosts:
- "prod-us1/*"
- "prod-apis/*"
- "istio-system/*"
下面配置是在prod-us1的namespace声明配置,该配置接受目的端口为9080并且HTTP协议的请求,并将其转发到侦听Unix套接字,出方向也做了很多
apiVersion: networking.istio.io/v1alpha3
kind: Sidecar
metadata:
name: default
namespace: prod-us1
spec:
ingress:
- port:
number: 9080
protocol: HTTP
name: somename
defaultEndpoint: unix:///var/run/someuds.sock
egress:
- port:
number: 9080
protocol: HTTP
name: egresshttp
hosts:
- "prod-us1/*"
- hosts:
- "istio-system/*"
详细配置参考Sidecar
Envoyfilter
Envoyfilter是针对Envoy中的filter进行配置,envoy的流量控制流程如下
包含两类filter,在L4和L7。
- L4 filter包括
HTTP connection manager
,MySQL proxy
,Rate limit
,RBAC
,Redis proxy
,TCP proxy
等 - L7 filter是L4 filter中
HTTP connection manager
下面定义的filter, 主要包括:CORS
,External Authorization
,Fault Injection
,Health check
,JWT Authentication
,Lua
,Rate limit
,Router
等
无论L4还是L7的filter都是按照指定的次序执行,istio中使用的istio-proxy也是在envoy的基础上额外编译进了istio_authn,mixer等filter,以实现istio中的policy和telemetry等功能
envoy配置
listener:
filter_chains:
- filters: // L4 filter
- name: {L4-filter-name}
- name: envoy.http_connection_manager
config:
http_filters: // L7 filter
- name: {L7-filter-name}
示例EnvoyFilter配置
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: simple-envoy-filter
spec:
workloadLabels:
app: helloworld
filters:
- listenerMatch:
listenerType: SIDECAR_INBOUND
listenerProtocol: HTTP
insertPosition:
index: FIRST
filterType: HTTP
filterName: envoy.fault
filterConfig:
abort:
percentage:
numerator: 100
denominator: HUNDRED
httpStatus: 444
headers:
name: foo
exactMatch: bar
EnvoyFilter对象在xds接口生成的动态监听器配置为
dynamic_active_listeners:
- listener:
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
http_filters:
- name: envoy.fault
config:
abort:
percentage:
denominator: HUNDRED
numerator: 100
httpStatus: 444
headers:
name: bar
exactMatch: foo
- name: istio_authn
- name: mixer
详细配置参考EnvoyFilter