Skip to content

Commit e0434ff

Browse files
authored
Merge pull request #40832 from Zhuzhenghao/1.27/api-concepts
[zh] resync 1.27 api-concepts
2 parents 7a34c31 + 69881e6 commit e0434ff

File tree

1 file changed

+150
-56
lines changed

1 file changed

+150
-56
lines changed

content/zh-cn/docs/reference/using-api/api-concepts.md

Lines changed: 150 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,98 @@ the API server will send any `BOOKMARK` event even when requested.
375375
作为客户端,你可以在 **watch** 请求中设置 `allowWatchBookmarks=true` 查询参数来请求 `BOOKMARK` 事件,
376376
但你不应假设书签会在任何特定时间间隔返回,即使要求时,客户端也不能假设 API 服务器会发送任何 `BOOKMARK` 事件。
377377

378+
<!--
379+
## Streaming lists
380+
-->
381+
## 流式列表 {#streaming-lists}
382+
383+
{{< feature-state for_k8s_version="v1.27" state="alpha" >}}
384+
385+
<!--
386+
On large clusters, retrieving the collection of some resource types may result in
387+
a significant increase of resource usage (primarily RAM) on the control plane.
388+
In order to alleviate its impact and simplify the user experience of the **list** + **watch**
389+
pattern, Kubernetes v1.27 introduces as an alpha feature the support
390+
for requesting the initial state (previously requested via the **list** request) as part of
391+
the **watch** request.
392+
-->
393+
在大型集群检索某些资源类型的集合可能会导致控制平面的资源使用量(主要是 RAM)显著增加。
394+
为了减轻其影响并简化 **list** + **watch** 模式的用户体验,
395+
Kubernetes 1.27 版本引入了一个 alpha 功能,支持在 **watch** 请求中请求初始状态
396+
(之前在 **list** 请求中请求)。
397+
398+
<!--
399+
Provided that the `WatchList` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
400+
is enabled, this can be achieved by specifying `sendInitialEvents=true` as query string parameter
401+
in a **watch** request. If set, the API server starts the watch stream with synthetic init
402+
events (of type `ADDED`) to build the whole state of all existing objects followed by a
403+
[`BOOKMARK` event](/docs/reference/using-api/api-concepts/#watch-bookmarks)
404+
(if requested via `allowWatchBookmarks=true` option). The bookmark event includes the resource version
405+
to which is synced. After sending the bookmark event, the API server continues as for any other **watch**
406+
request.
407+
-->
408+
如果启用了 `WatchList` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
409+
可以通过在 **watch** 请求中指定 `sendInitialEvents=true` 作为查询字符串参数来实现这一功能。
410+
如果指定了这个参数,API 服务器将使用合成的初始事件(类型为 `ADDED`)来启动监视流,
411+
以构建所有现有对象的完整状态;如果请求还带有 `allowWatchBookmarks=true` 选项,
412+
则继续发送 [`BOOKMARK` 事件](/zh-cn/docs/reference/using-api/api-concepts/#watch-bookmarks)
413+
BOOKMARK 事件包括已被同步的资源版本。
414+
发送 BOOKMARK 事件后,API 服务器会像处理所有其他 **watch** 请求一样继续执行。
415+
416+
<!--
417+
When you set `sendInitialEvents=true` in the query string, Kubernetes also requires that you set
418+
`resourceVersionMatch` to `NotOlderThan` value.
419+
If you provided `resourceVersion` in the query string without providing a value or don't provide
420+
it at all, this is interpreted as a request for _consistent read_;
421+
the bookmark event is sent when the state is synced at least to the moment of a consistent read
422+
from when the request started to be processed. If you specify `resourceVersion` (in the query string),
423+
the bookmark event is sent when the state is synced at least to the provided resource version.
424+
-->
425+
当你在查询字符串中设置 `sendInitialEvents=true` 时,
426+
Kubernetes 还要求你将 `resourceVersionMatch` 的值设置为 `NotOlderThan`
427+
如果你在查询字符串中提供 `resourceVersion` 而没有提供值或者根本没有提供这个参数,
428+
这一请求将被视为 **一致性读(Consistent Read)** 请求;
429+
当状态至少被同步到开始处理一致性读操作时,才会发送 BOOKMARK 事件。
430+
如果你(在查询字符串中)指定了 `resourceVersion`,则只要需要等状态同步到所给资源版本时,
431+
BOOKMARK 事件才会被发送。
432+
433+
<!--
434+
### Example {#example-streaming-lists}
435+
-->
436+
### 示例 {#example-streaming-lists}
437+
438+
<!--
439+
An example: you want to watch a collection of Pods. For that collection, the current resource version
440+
is 10245 and there are two pods: `foo` and `bar`. Then sending the following request (explicitly requesting
441+
_consistent read_ by setting empty resource version using `resourceVersion=`) could result
442+
in the following sequence of events:
443+
-->
444+
举个例子:你想监视一组 Pod。对于该集合,当前资源版本为 10245,并且有两个 Pod:`foo``bar`
445+
接下来你发送了以下请求(通过使用 `resourceVersion=` 设置空的资源版本来明确请求 **一致性读**),
446+
这样做的结果是可能收到如下事件序列:
447+
```console
448+
GET /api/v1/namespaces/test/pods?watch=1&sendInitialEvents=true&allowWatchBookmarks=true&resourceVersion=&resourceVersionMatch=NotOlderThan
449+
---
450+
200 OK
451+
Transfer-Encoding: chunked
452+
Content-Type: application/json
453+
454+
{
455+
"type": "ADDED",
456+
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "8467", "name": "foo"}, ...}
457+
}
458+
{
459+
"type": "ADDED",
460+
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "5726", "name": "bar"}, ...}
461+
}
462+
{
463+
"type": "BOOKMARK",
464+
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "10245"} }
465+
}
466+
...
467+
<followed by regular watch stream starting from resourceVersion="10245">
468+
```
469+
378470
<!--
379471
## Retrieving large results sets in chunks
380472
-->
@@ -1105,49 +1197,20 @@ These situations are:
11051197
2. 字段在对象中重复出现。
11061198

11071199
<!--
1108-
### Setting the field validation level
1200+
### Validation for unrecognized or duplicate fields (#setting-the-field-validation-level)
11091201
-->
1110-
### 设置字段校验层级 {#setting-the-field-validation-level}
1202+
### 检查无法识别或重复的字段 {#setting-the-field-validation-level}
11111203

1112-
{{< feature-state for_k8s_version="v1.25" state="beta" >}}
1204+
{{< feature-state for_k8s_version="v1.27" state="stable" >}}
11131205

11141206
<!--
1115-
Provided that the `ServerSideFieldValidation` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled (disabled
1116-
by default in 1.23 and 1.24, enabled by default starting in 1.25), you can take
1117-
advantage of server side field validation to catch these unrecognized fields.
1207+
From 1.25 onward, unrecognized or duplicate fields in an object are detected via
1208+
validation on the server when you use HTTP verbs that can submit data (`POST`, `PUT`, and `PATCH`). Possible levels of
1209+
validation are `Ignore`, `Warn` (default), and `Strict`.
11181210
-->
1119-
如果启用了 `ServerSideFieldValidation` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
1120-
(在 1.23 和 1.24 中默认处于禁用状态,从 1.25 开始默认启用),
1121-
你可以用服务端的字段校验来抓取这些未能识别的字段。
1122-
1123-
<!--
1124-
When you use HTTP verbs that can submit data (`POST`, `PUT`, and `PATCH`), field
1125-
validation gives you the option to choose how you would like to be notified of
1126-
these fields that are being dropped by the API server. Possible levels of
1127-
validation are `Ignore`, `Warn`, and `Strict`.
1128-
-->
1129-
使用可以提交数据的 HTTP 动词(`POST`、`PUT`、`PATCH`)时,可以在字段校验中设置
1130-
API 服务器丢弃字段时的通知设置。通知层级可能包括 `Ignore`、`Warn` 和 `Strict`。
1131-
1132-
{{< note >}}
1133-
<!--
1134-
If you submit a request that specifies an unrecognized field, and that is also invalid for
1135-
a different reason (for example, the request provides a string value where the API expects
1136-
an integer), then the API server responds with a 400 Bad Request error response.
1137-
You always receive an error response in this case, no matter what field validation level you requested.
1138-
-->
1139-
如果你所提交的请求中指定了无法识别的字段,并且该请求由于其他某种原因无法生效
1140-
(例如:请求提供的是字符值,而 API 需要整数),那么 API 服务器会返回 400 Bad Request(400 请求无效)错误响应码。
1141-
1142-
在这种情况下,无论请求哪个层级的字段校验,都总会收到错误响应。
1143-
{{< /note >}}
1144-
1145-
<!--
1146-
Field validation is set by the `fieldValidation` query parameter. The three
1147-
values that you can provide for this parameter are:
1148-
-->
1149-
字段校验需要通过 `fieldValidation` 查询参数进行设置。此参数接受三种值:
1150-
1211+
从 1.25 开始,当使用可以提交数据的 HTTP 动词(`POST`、`PUT` 和 `PATCH`)时,
1212+
将通过服务器上的校验检测到对象中无法识别或重复的字段。
1213+
校验的级别可以是 `Ignore`、`Warn`(默认值) 和 `Strict` 之一。
11511214
<!--
11521215
: The API server succeeds in handling the request as it would without the erroneous fields
11531216
being set, dropping all unknown and duplicate fields and giving no indication it
@@ -1178,6 +1241,29 @@ detected.
11781241
: API 服务器检测到任何未知字段或重复字段时,拒绝处理请求并返回 400 Bad Request 错误。
11791242
来自 API 服务器的响应消息列出了 API 检测到的所有未知字段或重复字段。
11801243

1244+
<!--
1245+
The field validation level is set by the `fieldValidation` query parameter.
1246+
-->
1247+
字段校验级别可通过查询参数 `fieldValidation` 来设置。
1248+
1249+
{{< note >}}
1250+
<!--
1251+
If you submit a request that specifies an unrecognized field, and that is also invalid for
1252+
a different reason (for example, the request provides a string value where the API expects
1253+
an integer for a known field), then the API server responds with a 400 Bad Request error, but will
1254+
not provide any information on unknown or duplicate fields (only which fatal
1255+
error it encountered first).
1256+
1257+
You always receive an error response in this case, no matter what field validation level you requested.
1258+
-->
1259+
如果你提交的请求中设置了一个无法被识别的字段,并且该请求存在因其他原因引起的不合法
1260+
(例如,请求为某已知字段提供了一个字符串值,而 API 期望该字段为整数),
1261+
那么 API 服务器会以 400 Bad Request 错误作出响应,但不会提供有关未知或重复字段的任何信息
1262+
(仅提供它首先遇到的致命错误)。
1263+
1264+
在这种情况下,不管你设置哪种字段校验级别,你总会收到出错响应。
1265+
{{< /note >}}
1266+
11811267
<!--
11821268
Tools that submit requests to the server (such as `kubectl`), might set their own
11831269
defaults that are different from the `Warn` validation level that the API server uses
@@ -1187,26 +1273,31 @@ by default.
11871273
校验层级不同。
11881274

11891275
<!--
1190-
The `kubectl` tool uses the `--validate` flag to set the level of field validation.
1191-
Historically `--validate` was used to toggle client-side validation on or off as
1192-
a boolean flag. Since Kubernetes 1.25, kubectl uses
1193-
server-side field validation when sending requests to a server with this feature
1194-
enabled. Validation will fall back to client-side only when it cannot connect
1195-
to an API server with field validation enabled.
1276+
The `kubectl` tool uses the `--validate` flag to set the level of field
1277+
validation. It accepts the values `ignore`, `warn`, and `strict` while
1278+
also accepting the values `true` (equivalent to `strict`) and `false`
1279+
(equivalent to `ignore`). The default validation setting for kubectl is
1280+
`--validate=true`, which means strict server-side field validation.
1281+
1282+
When kubectl cannot connect to an API server with field validation (API servers
1283+
prior to Kubernetes 1.27), it will fall back to using client-side validation.
1284+
Client-side validation will be removed entirely in a future version of kubectl.
11961285
-->
11971286
`kubectl` 工具使用 `--validate` 标志设置字段校验层级。
1198-
之前 `--validate` 被作为布尔值开启或关闭客户段的校验功能。
1199-
从 Kubernetes 1.25 开始,kubectl 向启用字段校验的服务器发送请求时使用服务端字段校验。
1200-
只有无法连接启用了字段校验的 API 服务器时,才会恢复使用客户端的字段校验。
1287+
该字段可取的值包括 `ignore`、`warn` 和 `strict`,同时还接受值 `true`(相当于 `strict`)和
1288+
`false`(相当于 `ignore`)。
1289+
kubectl 默认的校验设置是 `--validate=true` ,这意味着执行严格的服务端字段校验。
1290+
1291+
当 kubectl 无法连接到启用字段校验的 API 服务器(Kubernetes 1.27 之前的 API 服务器)时,
1292+
将回退到使用客户端的字段校验。
1293+
客户端校验将在 kubectl 未来版本中被完全删除。
1294+
{{< note >}}
12011295
<!--
1202-
It accepts the values `ignore`, `warn`,
1203-
and `strict` while also accepting the values `true` (equivalent to `strict`) and `false`
1204-
(equivalent to `ignore`). The default validation setting for kubectl is `--validate=true`,
1205-
which means strict server-side field validation.
1296+
Prior to Kubernetes 1.25 `kubectl --validate` was used to toggle client-side validation on or off as
1297+
a boolean flag.
12061298
-->
1207-
`kubectl` 接受 `ignore`、`warn`、`strict` 值,同时也接受 `true`(等效于 `strict`)
1208-
和 `false`(等效于 `ignore`)。kubectl 的字段校验默认配置为 `--validate=true`,
1209-
即服务端的 `strict` 级字段校验。
1299+
在 Kubernetes 1.25 之前,`kubectl --validate` 是用来开启或关闭客户端校验的布尔标志的命令。
1300+
{{< /note >}}
12101301

12111302
<!--
12121303
## Dry-run
@@ -1312,7 +1403,10 @@ generated fields may differ.
13121403
<!--
13131404
### Generated values
13141405

1315-
Some values of an object are typically generated before the object is persisted. It is important not to rely upon the values of these fields set by a dry-run request, since these values will likely be different in dry-run mode from when the real request is made. Some of these fields are:
1406+
Some values of an object are typically generated before the object is persisted. It
1407+
is important not to rely upon the values of these fields set by a dry-run request,
1408+
since these values will likely be different in dry-run mode from when the real
1409+
request is made. Some of these fields are:
13161410

13171411
* `name`: if `generateName` is set, `name` will have a unique random name
13181412
* `creationTimestamp` / `deletionTimestamp`: records the time of creation/deletion
@@ -1682,7 +1776,7 @@ For watch, the semantics of resource version are:
16821776
{{< /table >}}
16831777

16841778
<!--
1685-
The meaning of the **watch** semantics are:
1779+
The meaning of those **watch** semantics are:
16861780

16871781
Get State and Start at Any
16881782
: {{< caution >}} Watches initialized this way may return arbitrarily stale

0 commit comments

Comments
 (0)