策略管理
Mixer 为应用程序和基础架构后端之间提供了一个通用的策略控制层,负责先决条件检查(如认证授权)、配额管理并从 Envoy 代理中收集遥测数据等。
Mixer 是高度模块化和可扩展的组件。他的一个关键功能就是把不同后端的策略和遥测收集系统的细节抽象出来,使得 Istio 的其余部分对这些后端不知情。Mixer 处理不同基础设施后端的灵活性是通过使用通用插件模型实现的。每个插件都被称为 Adapter,Mixer通过它们与不同的基础设施后端连接,这些后端可提供核心功能,例如日志、监控、配额、ACL 检查等。通过配置能够决定在运行时使用的确切的适配器套件,并且可以轻松扩展到新的或定制的基础设施后端。

实现原理

本质上,Mixer 是一个 属性 处理机,进入 Mixer 的请求带有一系列的属性,Mixer 按照不同的处理阶段处理:
    通过全局 Adapters 为请求引入新的属性
    通过解析(Resolution)识别要用于处理请求的配置资源
    处理属性,生成 Adapter 参数
    分发请求到各个 Adapters 后端处理

流量限制示例

1
apiVersion: "config.istio.io/v1alpha2"
2
kind: memquota
3
metadata:
4
name: handler
5
namespace: istio-system
6
spec:
7
quotas:
8
- name: requestcount.quota.istio-system
9
maxAmount: 5000
10
validDuration: 1s
11
# The first matching override is applied.
12
# A requestcount instance is checked against override dimensions.
13
overrides:
14
# The following override applies to 'ratings' when
15
# the source is 'reviews'.
16
- dimensions:
17
destination: ratings
18
source: reviews
19
maxAmount: 1
20
validDuration: 1s
21
# The following override applies to 'ratings' regardless
22
# of the source.
23
- dimensions:
24
destination: ratings
25
maxAmount: 100
26
validDuration: 1s
27
28
---
29
apiVersion: "config.istio.io/v1alpha2"
30
kind: quota
31
metadata:
32
name: requestcount
33
namespace: istio-system
34
spec:
35
dimensions:
36
source: source.labels["app"] | source.service | "unknown"
37
sourceVersion: source.labels["version"] | "unknown"
38
destination: destination.labels["app"] | destination.service | "unknown"
39
destinationVersion: destination.labels["version"] | "unknown"
40
41
---
42
apiVersion: "config.istio.io/v1alpha2"
43
kind: rule
44
metadata:
45
name: quota
46
namespace: istio-system
47
spec:
48
actions:
49
- handler: handler.memquota
50
instances:
51
- requestcount.quota
52
---
53
apiVersion: config.istio.io/v1alpha2
54
kind: QuotaSpec
55
metadata:
56
name: request-count
57
namespace: istio-system
58
spec:
59
rules:
60
- quotas:
61
- charge: 1
62
quota: requestcount
63
---
64
apiVersion: config.istio.io/v1alpha2
65
kind: QuotaSpecBinding
66
metadata:
67
name: request-count
68
namespace: istio-system
69
spec:
70
quotaSpecs:
71
- name: request-count
72
namespace: istio-system
73
services:
74
- name: ratings
75
- name: reviews
76
- name: details
77
- name: productpage
Copied!

参考文档

最近更新 2yr ago