Skip to content

Commit 2229800

Browse files
authored
Merge pull request #43025 from windsonsea/flowct
[zh] Sync flow-control.md
2 parents 214a186 + 4732411 commit 2229800

File tree

2 files changed

+237
-1
lines changed

2 files changed

+237
-1
lines changed

content/zh-cn/docs/concepts/cluster-administration/flow-control.md

Lines changed: 212 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ that originate from outside your cluster.
831831
则可以配置规则,阻止所有来自集群外部的健康检查请求。
832832
{{< /caution >}}
833833

834-
{{% code file="priority-and-fairness/health-for-strangers.yaml" %}}
834+
{{% code_sample file="priority-and-fairness/health-for-strangers.yaml" %}}
835835

836836
<!--
837837
## Diagnostics
@@ -1384,6 +1384,217 @@ APF 将以下两个头添加到每个 HTTP 响应消息中。
13841384
- `X-Kubernetes-PF-FlowSchema-UID` 保存相应请求被分类到的 FlowSchema 对象的 UID。
13851385
- `X-Kubernetes-PF-PriorityLevel-UID` 保存与该 FlowSchema 关联的 PriorityLevelConfiguration 对象的 UID。
13861386

1387+
<!--
1388+
## Good practices for using API Priority and Fairness
1389+
1390+
When a given priority level exceeds its permitted concurrency, requests can
1391+
experience increased latency or be dropped with an HTTP 429 (Too Many Requests)
1392+
error. To prevent these side effects of APF, you can modify your workload or
1393+
tweak your APF settings to ensure there are sufficient seats available to serve
1394+
your requests.
1395+
-->
1396+
## 使用 API 优先级和公平性的最佳实践 {#good-practices-for-using-api-priority-and-fairness}
1397+
1398+
当某个给定的优先级级别超过其所被允许的并发数时,请求可能会遇到延迟增加,
1399+
或以错误 HTTP 429 (Too Many Requests) 的形式被拒绝。
1400+
为了避免这些 APF 的副作用,你可以修改你的工作负载或调整你的 APF 设置,确保有足够的席位来处理请求。
1401+
1402+
<!--
1403+
To detect whether requests are being rejected due to APF, check the following
1404+
metrics:
1405+
1406+
- apiserver_flowcontrol_rejected_requests_total: the total number of requests
1407+
rejected per FlowSchema and PriorityLevelConfiguration.
1408+
- apiserver_flowcontrol_current_inqueue_requests: the current number of requests
1409+
queued per FlowSchema and PriorityLevelConfiguration.
1410+
- apiserver_flowcontrol_request_wait_duration_seconds: the latency added to
1411+
requests waiting in queues.
1412+
- apiserver_flowcontrol_priority_level_seat_utilization: the seat utilization
1413+
per PriorityLevelConfiguration.
1414+
-->
1415+
要检测请求是否由于 APF 而被拒绝,可以检查以下指标:
1416+
1417+
- apiserver_flowcontrol_rejected_requests_total:
1418+
每个 FlowSchema 和 PriorityLevelConfiguration 拒绝的请求总数。
1419+
- apiserver_flowcontrol_current_inqueue_requests:
1420+
每个 FlowSchema 和 PriorityLevelConfiguration 中排队的当前请求数。
1421+
- apiserver_flowcontrol_request_wait_duration_seconds:请求在队列中等待的延迟时间。
1422+
- apiserver_flowcontrol_priority_level_seat_utilization:
1423+
每个 PriorityLevelConfiguration 的席位利用率。
1424+
1425+
<!--
1426+
### Workload modifications {#good-practice-workload-modifications}
1427+
1428+
To prevent requests from queuing and adding latency or being dropped due to APF,
1429+
you can optimize your requests by:
1430+
-->
1431+
### 工作负载修改 {#good-practice-workload-modifications}
1432+
1433+
为了避免由于 APF 导致请求排队、延迟增加或被拒绝,你可以通过以下方式优化请求:
1434+
1435+
<!--
1436+
- Reducing the rate at which requests are executed. A fewer number of requests
1437+
over a fixed period will result in a fewer number of seats being needed at a
1438+
given time.
1439+
-->
1440+
- 减少请求执行的速率。在固定时间段内减少请求数量将导致在某一给定时间点需要的席位数更少。
1441+
1442+
<!--
1443+
- Avoid issuing a large number of expensive requests concurrently. Requests can
1444+
be optimized to use fewer seats or have lower latency so that these requests
1445+
hold those seats for a shorter duration. List requests can occupy more than 1
1446+
seat depending on the number of objects fetched during the request. Restricting
1447+
the number of objects retrieved in a list request, for example by using
1448+
pagination, will use less total seats over a shorter period. Furthermore,
1449+
replacing list requests with watch requests will require lower total concurrency
1450+
shares as watch requests only occupy 1 seat during its initial burst of
1451+
notifications. If using streaming lists in versions 1.27 and later, watch
1452+
requests will occupy the same number of seats as a list request for its initial
1453+
burst of notifications because the entire state of the collection has to be
1454+
streamed. Note that in both cases, a watch request will not hold any seats after
1455+
this initial phase.
1456+
-->
1457+
- 避免同时发出大量消耗较多席位的请求。请求可以被优化为使用更少的席位或降低延迟,
1458+
使这些请求占用席位的时间变短。列表请求根据请求期间获取的对象数量可能会占用多个席位。
1459+
例如通过使用分页等方式限制列表请求中取回的对象数量,可以在更短时间内使用更少的总席位数。
1460+
此外,将列表请求替换为监视请求将需要更低的总并发份额,因为监视请求仅在初始的通知突发阶段占用 1 个席位。
1461+
如果在 1.27 及更高版本中使用流式列表,因为集合的整个状态必须以流式传输,
1462+
所以监视请求在其初始的通知突发阶段将占用与列表请求相同数量的席位。
1463+
请注意,在这两种情况下,监视请求在此初始阶段之后将不再保留任何席位。
1464+
1465+
<!--
1466+
Keep in mind that queuing or rejected requests from APF could be induced by
1467+
either an increase in the number of requests or an increase in latency for
1468+
existing requests. For example, if requests that normally take 1s to execute
1469+
start taking 60s, it is possible that APF will start rejecting requests because
1470+
requests are occupying seats for a longer duration than normal due to this
1471+
increase in latency. If APF starts rejecting requests across multiple priority
1472+
levels without a significant change in workload, it is possible there is an
1473+
underlying issue with control plane performance rather than the workload or APF
1474+
settings.
1475+
-->
1476+
请注意,由于请求数量增加或现有请求的延迟增加,APF 可能会导致请求排队或被拒绝。
1477+
例如,如果通常需要 1 秒执行的请求开始需要 60 秒,由于延迟增加,
1478+
请求所占用的席位时间可能超过了正常情况下的时长,APF 将开始拒绝请求。
1479+
如果在没有工作负载显著变化的情况下,APF 开始在多个优先级级别上拒绝请求,
1480+
则可能存在控制平面性能的潜在问题,而不是工作负载或 APF 设置的问题。
1481+
1482+
<!--
1483+
### Priority and fairness settings {#good-practice-apf-settings}
1484+
1485+
You can also modify the default FlowSchema and PriorityLevelConfiguration
1486+
objects or create new objects of these types to better accommodate your
1487+
workload.
1488+
1489+
APF settings can be modified to:
1490+
1491+
- Give more seats to high priority requests.
1492+
- Isolate non-essential or expensive requests that would starve a concurrency
1493+
level if it was shared with other flows.
1494+
-->
1495+
### 优先级和公平性设置 {#good-practice-apf-settings}
1496+
1497+
你还可以修改默认的 FlowSchema 和 PriorityLevelConfiguration 对象,
1498+
或创建新的对象来更好地容纳你的工作负载。
1499+
1500+
APF 设置可以被修改以实现下述目标:
1501+
1502+
- 给予高优先级请求更多的席位。
1503+
- 隔离那些非必要或开销大的请求,因为如果与其他流共享,这些请求可能会耗尽所有并发级别。
1504+
1505+
<!--
1506+
#### Give more seats to high priority requests
1507+
-->
1508+
#### 给予高优先级请求更多的席位
1509+
1510+
<!--
1511+
1. If possible, the number of seats available across all priority levels for a
1512+
particular `kube-apiserver` can be increased by increasing the values for the
1513+
`max-requests-inflight` and `max-mutating-requests-inflight` flags. Alternatively,
1514+
horizontally scaling the number of `kube-apiserver` instances will increase the
1515+
total concurrency per priority level across the cluster assuming there is
1516+
sufficient load balancing of requests.
1517+
-->
1518+
1. 如果有可能,你可以通过提高 `max-requests-inflight``max-mutating-requests-inflight`
1519+
参数的值为特定 `kube-apiserver` 提高所有优先级级别均可用的席位数量。另外,
1520+
如果在请求的负载均衡足够好的情况下,水平扩缩 `kube-apiserver` 实例的数量将提高集群中每个优先级级别的总并发数。
1521+
1522+
<!--
1523+
1. You can create a new FlowSchema which references a PriorityLevelConfiguration
1524+
with a larger concurrency level. This new PriorityLevelConfiguration could be an
1525+
existing level or a new level with its own set of nominal concurrency shares.
1526+
For example, a new FlowSchema could be introduced to change the
1527+
PriorityLevelConfiguration for your requests from global-default to workload-low
1528+
to increase the number of seats available to your user. Creating a new
1529+
PriorityLevelConfiguration will reduce the number of seats designated for
1530+
existing levels. Recall that editing a default FlowSchema or
1531+
PriorityLevelConfiguration will require setting the
1532+
`apf.kubernetes.io/autoupdate-spec` annotation to false.
1533+
-->
1534+
2. 你可以创建一个新的 FlowSchema,在其中引用并发级别更高的 PriorityLevelConfiguration。
1535+
这个新的 PriorityLevelConfiguration 可以是现有的级别,也可以是具有自己一组额定并发份额的新级别。
1536+
例如,你可以引入一个新的 FlowSchema 来将请求的 PriorityLevelConfiguration
1537+
从全局默认值更改为工作负载较低的级别,以增加用户可用的席位数。
1538+
创建一个新的 PriorityLevelConfiguration 将减少为现有级别指定的席位数。
1539+
请注意,编辑默认的 FlowSchema 或 PriorityLevelConfiguration 需要将
1540+
`apf.kubernetes.io/autoupdate-spec` 注解设置为 false。
1541+
1542+
<!--
1543+
1. You can also increase the NominalConcurrencyShares for the
1544+
PriorityLevelConfiguration which is serving your high priority requests.
1545+
Alternatively, for versions 1.26 and later, you can increase the LendablePercent
1546+
for competing priority levels so that the given priority level has a higher pool
1547+
of seats it can borrow.
1548+
-->
1549+
3. 你还可以为服务于高优先级请求的 PriorityLevelConfiguration 提高 NominalConcurrencyShares。
1550+
此外在 1.26 及更高版本中,你可以为有竞争的优先级级别提高 LendablePercent,以便给定优先级级别可以借用更多的席位。
1551+
1552+
<!--
1553+
#### Isolate non-essential requests from starving other flows
1554+
1555+
For request isolation, you can create a FlowSchema whose subject matches the
1556+
user making these requests or create a FlowSchema that matches what the request
1557+
is (corresponding to the resourceRules). Next, you can map this FlowSchema to a
1558+
PriorityLevelConfiguration with a low share of seats.
1559+
-->
1560+
#### 隔离非关键请求以免饿死其他流
1561+
1562+
为了进行请求隔离,你可以创建一个 FlowSchema,使其主体与发起这些请求的用户匹配,
1563+
或者创建一个与请求内容匹配(对应 resourceRules)的 FlowSchema。
1564+
接下来,你可以将该 FlowSchema 映射到一个具有较低席位份额的 PriorityLevelConfiguration。
1565+
1566+
<!--
1567+
For example, suppose list event requests from Pods running in the default namespace
1568+
are using 10 seats each and execute for 1 minute. To prevent these expensive
1569+
requests from impacting requests from other Pods using the existing service-accounts
1570+
FlowSchema, you can apply the following FlowSchema to isolate these list calls
1571+
from other requests.
1572+
1573+
Example FlowSchema object to isolate list event requests:
1574+
-->
1575+
例如,假设来自 default 名字空间中运行的 Pod 的每个事件列表请求使用 10 个席位,并且执行时间为 1 分钟。
1576+
为了防止这些开销大的请求影响使用现有服务账号 FlowSchema 的其他 Pod 的请求,你可以应用以下
1577+
FlowSchema 将这些列表调用与其他请求隔离开来。
1578+
1579+
用于隔离列表事件请求的 FlowSchema 对象示例:
1580+
1581+
{{% code_sample file="priority-and-fairness/list-events-default-service-account.yaml" %}}
1582+
1583+
<!--
1584+
- This FlowSchema captures all list event calls made by the default service
1585+
account in the default namespace. The matching precedence 8000 is lower than the
1586+
value of 9000 used by the existing service-accounts FlowSchema so these list
1587+
event calls will match list-events-default-service-account rather than
1588+
service-accounts.
1589+
- The catch-all PriorityLevelConfiguration is used to isolate these requests.
1590+
The catch-all priority level has a very small concurrency share and does not
1591+
queue requests.
1592+
-->
1593+
- 这个 FlowSchema 用于抓取 default 名字空间中默认服务账号所发起的所有事件列表调用。
1594+
匹配优先级为 8000,低于现有服务账号 FlowSchema 所用的 9000,因此这些列表事件调用将匹配到
1595+
list-events-default-service-account 而不是服务账号。
1596+
- 通用 PriorityLevelConfiguration 用于隔离这些请求。通用优先级级别具有非常小的并发份额,并且不对请求进行排队。
1597+
13871598
## {{% heading "whatsnext" %}}
13881599

13891600
<!--
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: flowcontrol.apiserver.k8s.io/v1beta3
2+
kind: FlowSchema
3+
metadata:
4+
name: list-events-default-service-account
5+
spec:
6+
distinguisherMethod:
7+
type: ByUser
8+
matchingPrecedence: 8000
9+
priorityLevelConfiguration:
10+
name: catch-all
11+
rules:
12+
- resourceRules:
13+
- apiGroups:
14+
- '*'
15+
namespaces:
16+
- default
17+
resources:
18+
- events
19+
verbs:
20+
- list
21+
subjects:
22+
- kind: ServiceAccount
23+
serviceAccount:
24+
name: default
25+
namespace: default

0 commit comments

Comments
 (0)