github.com/gocrane/crane@v0.11.0/docs/tutorials/qos-interference-detection-and-active-avoidance.zh.md (about) 1 ## Qos Ensurance 架构 2 Qos ensurance 的架构如下图所示。它包含三个模块。 3 4 1. `State Collector`:定期收集指标 5 2. `Anomaly Analyzer`:使用收集指标,以分析节点是否发生异常 6 3. `Action Executor`:执行回避动作,包括 Disable Scheduling、Throttle 和 Eviction。 7 8  9 10 主要流程: 11 12 1. `State Collector` 从 kube-apiserver 同步策略。 13 2. 如果策略发生更改,`State Collector`会更新指标收集规则。 14 3. `State Collector`定期收集指标。 15 4. `State Collector`将指标传输到`Anomaly Analyzer`。 16 5. `Anomaly Analyzer`对所有规则进行范围分析,以分析达到的回避阈值或恢复阈值。 17 6. `Anomaly Analyzer`合并分析结果并通知`Action Executor`执行回避动作。 18 7. `Action Executor`根据分析结果执行动作。 19 20 ## 干扰检测和主动回避 21 22 ### 相关CR 23 AvoidanceAction主要定义了检测到干扰后需要执行的操作,包含了Disable Scheduling, throttle, eviction等几个操作,并且定义了其相关的一些参数。 24 25 NodeQOS主要定义了指标采集方式和参数,水位线指标相关参数,以及指标异常时关联的回避操作,同时通过label selector将上面的内容关联到指定的节点。 26 27 PodQOS定义了指定pod可以被执行的AvoidanceAction,通常和NodeQOS搭配起来,从节点和pod的维度共同限制执行动作的范围,PodQOS支持的seletor包含label selector, 28 还支持筛选特定QOSClass("BestEffort","Guaranteed"等),特定Priority,特定Namespace的pod,并且之间采用与的方式关联。 29 30 ### Disable Scheduling 31 32 定义 `AvoidanceAction`, `PodQOS`和 `NodeQOS`。 33 34 当节点 CPU 使用率触发回避阈值时,将该节点设置为禁用调度。 35 36 37 示例 YAML 如下所示: 38 39 ```yaml title="AvoidanceAction" 40 apiVersion: ensurance.crane.io/v1alpha1 41 kind: AvoidanceAction 42 metadata: 43 labels: 44 app: system 45 name: disablescheduling 46 spec: 47 description: disable schedule new pods to the node 48 coolDownSeconds: 300 #(1) 49 ``` 50 51 1. 节点从禁止调度状态到正常状态的最小等待时间 52 53 ```yaml title="NodeQOS" 54 apiVersion: ensurance.crane.io/v1alpha1 55 kind: NodeQOS 56 metadata: 57 name: "watermark1" 58 labels: 59 app: "system" 60 spec: 61 nodeQualityProbe: 62 timeoutSeconds: 10 63 nodeLocalGet: 64 localCacheTTLSeconds: 60 65 rules: 66 - name: "cpu-usage" 67 avoidanceThreshold: 2 #(1) 68 restoreThreshold: 2 #(2) 69 actionName: "disablescheduling" #(3) 70 strategy: "None" #(4) 71 metricRule: 72 name: "cpu_total_usage" #(5) 73 value: 4000 #(6) 74 ``` 75 76 1. 当达到阈值并持续多次,那么我们认为规则被触发 77 2. 当阈值未达到并继续多次, 那么我们认为规则已恢复 78 3. 关联到 AvoidanceAction 名称 79 4. 动作的策略,你可以将其设置为“预览”以不实际执行 80 5. 指标名称 81 6. 指标的阈值 82 83 ```yaml title="PodQOS" 84 apiVersion: ensurance.crane.io/v1alpha1 85 kind: PodQOS 86 metadata: 87 name: all-elastic-pods 88 spec: 89 allowedActions: #(1) 90 - eviction 91 labelSelector: #(2) 92 matchLabels: 93 preemptible_job: "true" 94 ``` 95 96 1. 被该PodQOS关联的pod允许被执行的action为eviction 97 2. 通过label selector关联具有preemptible_job: "true"的pod 98 99 请观看视频以了解更多`Disable Scheduling`的细节。 100 101 <script id="asciicast-480735" src="https://asciinema.org/a/480735.js" async></script> 102 103 ### Throttle 104 105 定义 `AvoidanceAction`, `NodeQOS` 和 `PodQOS`。 106 107 当节点 CPU 使用率触发回避阈值时,将执行节点的`Throttle Action`。 108 109 示例 YAML 如下所示: 110 111 ```yaml title="AvoidanceAction" 112 apiVersion: ensurance.crane.io/v1alpha1 113 kind: AvoidanceAction 114 metadata: 115 name: throttle 116 labels: 117 app: system 118 spec: 119 coolDownSeconds: 300 120 throttle: 121 cpuThrottle: 122 minCPURatio: 10 #(1) 123 stepCPURatio: 10 #(2) 124 description: "throttle low priority pods" 125 ``` 126 127 1. CPU 配额的最小比例,如果 pod 被限制低于这个比例,就会被设置为这个。 128 129 130 2. 该配置设置给`Throttle Action`。它将在每个触发的回避动作中减少这个 CPU 配额占比。它会在每个恢复动作中增加这个 CPU 配额占比。 131 132 ```yaml title="NodeQOS" 133 apiVersion: ensurance.crane.io/v1alpha1 134 kind: NodeQOS 135 metadata: 136 name: "watermark2" 137 labels: 138 app: "system" 139 spec: 140 nodeQualityProbe: 141 timeoutSeconds: 10 142 nodeLocalGet: 143 localCacheTTLSeconds: 60 144 rules: 145 - name: "cpu-usage" 146 avoidanceThreshold: 2 147 restoredThreshold: 2 148 actionName: "throttle" 149 strategy: "None" 150 metricRule: 151 name: "cpu_total_usage" 152 value: 6000 153 ``` 154 155 ```yaml title="PodQOS" 156 apiVersion: ensurance.crane.io/v1alpha1 157 kind: PodQOS 158 metadata: 159 name: all-be-pods 160 spec: 161 allowedActions: 162 - throttle 163 scopeSelector: 164 matchExpressions: 165 - operator: In 166 scopeName: QOSClass 167 values: 168 - BestEffort 169 ``` 170 171 ### Eviction 172 173 下面的 YAML 是另一种情况,当节点 CPU 使用率触发阈值时,节点上的低优先级 pod 将被驱逐。 174 175 ```yaml title="AvoidanceAction" 176 apiVersion: ensurance.crane.io/v1alpha1 177 kind: AvoidanceAction 178 metadata: 179 name: eviction 180 labels: 181 app: system 182 spec: 183 coolDownSeconds: 300 184 eviction: 185 terminationGracePeriodSeconds: 30 #(1) 186 description: "evict low priority pods" 187 ``` 188 189 pod 需要优雅终止的持续时间(以秒为单位)。 190 191 ```yaml title="NodeQOS" 192 apiVersion: ensurance.crane.io/v1alpha1 193 kind: NodeQOS 194 metadata: 195 name: "watermark3" 196 labels: 197 app: "system" 198 spec: 199 nodeQualityProbe: 200 timeoutSeconds: 10 201 nodeLocalGet: 202 localCacheTTLSeconds: 60 203 rules: 204 - name: "cpu-usage" 205 avoidanceThreshold: 2 206 restoreThreshold: 2 207 actionName: "eviction" 208 strategy: "Preview" #(1) 209 metricRule: 210 name: "cpu_total_usage" 211 value: 6000 212 ``` 213 214 ```yaml title="PodQOS" 215 apiVersion: ensurance.crane.io/v1alpha1 216 kind: PodQOS 217 metadata: 218 name: all-elastic-pods 219 spec: 220 allowedActions: 221 - eviction 222 labelSelector: 223 matchLabels: 224 preemptible_job: "true" 225 ``` 226 227 回避动作策略。当设置为`Preview`时,将不会被实际执行 228 229 ### 支持的水位线指标 230 Name | Description 231 ---------|------------- 232 cpu_total_usage | node cpu usage 233 cpu_total_utilization | node cpu utilization percent 234 memory_total_usage | node mem usage 235 memory_total_utilization| node mem utilization percent 236 237 具体可以参考examples/ensurance下的例子 238 239 ### 与弹性资源搭配使用 240 为了避免主动回避操作对于高优先级业务的影响,比如误驱逐了重要业务,建议使用PodQOS关联使用了弹性资源的workload,这样在执行动作的时候只会影响这些使用了空闲资源的workload, 241 保证了节点上的核心业务的稳定。 242 243 弹性资源的内容可以参见qos-dynamic-resource-oversold-and-limit.zh.md。