kube-apiserver限流配置

k8s v1.19.0

普通限流

客户端访问kube-apiserver,限流参数有max-mutating-requests-inflight(默认值是200,对应操作类请求)和max-requests-inflight(默认值是400,对应查询类请求)。

staging/src/k8s.io/apiserver/pkg/server/filters/maxinflight.go
WithMaxInFlightLimit函数
分别创建容量为max-requests-inflight和max-mutating-requests-inflight的channel,在channel中有余量情况下才能处理请求,没有余量时直接丢弃,不是每秒限流值。

开启APF

API优先级和公平性(APF)解决多个客户端之间请求相互影响的问题,避免某个客户端请求量大导致别的客户端因限流而处理慢。其中,优先级指高优先级请求比低优先级优先处理,公平性指同级别的请求公平处理。
从k8s 1.20开始,APIPriorityAndFairness门控默认开启。

开启APF,kube-apiserver增加启动参数。
- --runtime-config=flowcontrol.apiserver.k8s.io/v1alpha1=true
- --feature-gates=APIPriorityAndFairness=true

APF限流

请求进入kube-apiserver后,根据FlowSchema拆分成流,FlowSchema绑定优先级。
默认FlowSchema和PriorityLevelConfiguration

kube-apiserver总并发量=max- requests-inflight+max-mutating-requests-inflight,总并发量分配到不同优先级。
global-default的flowschema spec,FlowSchema+Distinguisher确定flow。

global-default的prioritylevelconfiguration spec。

参考资料

https://kubernetes.io/zh-cn/docs/reference/command-line-tools-reference/feature-gates/

 

posted on 2024-02-12 14:16  王景迁  阅读(171)  评论(0编辑  收藏  举报

导航