Skip to content

Commit 851c27f

Browse files
committed
[zh] Resync using-api/api-concepts.md
1 parent c63a9ca commit 851c27f

File tree

1 file changed

+73
-57
lines changed

1 file changed

+73
-57
lines changed

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

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ primary resources via the standard HTTP verbs (POST, PUT, PATCH, DELETE,
2121
GET).
2222
2323
For some resources, the API includes additional subresources that allow
24-
fine grained authorization (such as separate views for Pod details and
24+
fine-grained authorization (such as separate views for Pod details and
2525
log retrievals), and can accept and serve those resources in different
2626
representations for convenience or efficiency.
2727
-->
@@ -117,7 +117,7 @@ example: Nodes), and so their names must be unique across the whole cluster.
117117
### API verbs
118118
119119
Almost all object resource types support the standard HTTP verbs - GET, POST, PUT, PATCH,
120-
and DELETE. Kubernetes also uses its own verbs, which are often written lowercase to distinguish
120+
and DELETE. Kubernetes also uses its own verbs, which are often written in lowercase to distinguish
121121
them from HTTP verbs.
122122
123123
Kubernetes uses the term **list** to describe returning a [collection](#collections) of
@@ -184,9 +184,12 @@ The following paths are used to retrieve collections and resources:
184184
185185
* Namespace-scoped resources:
186186
187-
* `GET /apis/GROUP/VERSION/RESOURCETYPE` - return the collection of all instances of the resource type across all namespaces
188-
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE` - return collection of all instances of the resource type in NAMESPACE
189-
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME` - return the instance of the resource type with NAME in NAMESPACE
187+
* `GET /apis/GROUP/VERSION/RESOURCETYPE` - return the collection of all
188+
instances of the resource type across all namespaces
189+
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE` - return
190+
collection of all instances of the resource type in NAMESPACE
191+
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME` -
192+
return the instance of the resource type with NAME in NAMESPACE
190193
-->
191194
你还可以访问资源集合(例如:列出所有 Node)。以下路径用于检索集合和资源:
192195

@@ -198,8 +201,10 @@ The following paths are used to retrieve collections and resources:
198201
* 名字空间作用域的资源:
199202

200203
* `GET /apis/GROUP/VERSION/RESOURCETYPE` - 返回所有名字空间中指定资源类型的全部实例的集合
201-
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE` - 返回名字空间 NAMESPACE 内给定资源类型的全部实例的集合
202-
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME` - 返回名字空间 NAMESPACE 中给定资源类型的名称为 NAME 的实例
204+
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE` -
205+
返回名字空间 NAMESPACE 内给定资源类型的全部实例的集合
206+
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME` -
207+
返回名字空间 NAMESPACE 中给定资源类型的名称为 NAME 的实例
203208

204209
<!--
205210
Since a namespace is a cluster-scoped resource type, you can retrieve the list
@@ -334,7 +339,9 @@ Kubernetes API 默认使用 [JSON](https://www.json.org/json-en.html) 来编码
334339
<!--
335340
### YAML resource encoding {#yaml-encoding}
336341
337-
Kubernetes also supports the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html) media type for both requests and responses. [`YAML`](https://yaml.org/) can be used for defining Kubernetes manifests and API interactions.
342+
Kubernetes also supports the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html)
343+
media type for both requests and responses. [`YAML`](https://yaml.org/)
344+
can be used for defining Kubernetes manifests and API interactions.
338345
339346
For example:
340347
-->
@@ -408,7 +415,7 @@ Kubernetes uses an envelope wrapper to encode [Protobuf](https://protobuf.dev/)
408415
That wrapper starts with a 4 byte magic number to help identify content in disk or in etcd as Protobuf
409416
(as opposed to JSON). The 4 byte magic number data is followed by a Protobuf encoded wrapper message, which
410417
describes the encoding and type of the underlying object. Within the Protobuf wrapper message,
411-
the inner object data is recorded using the `raw` field of Unknown (see the [IDL](##protobuf-encoding-idl)
418+
the inner object data is recorded using the `raw` field of Unknown (see the [IDL](#protobuf-encoding-idl)
412419
for more detail).
413420
-->
414421
### Kubernetes Protobuf 编码 {#protobuf-encoding}
@@ -417,7 +424,7 @@ Kubernetes 使用封套形式来对 [Protobuf](https://protobuf.dev/) 响应进
417424
封套外层由 4 个字节的特殊数字开头,便于从磁盘文件或 etcd 中辩识 Protobuf
418425
格式的(而不是 JSON)数据。这个 4 字节的特殊数字后跟一个 Protobuf 编码的封套消息,
419426
此消息描述了下层对象的编码和类型。在 Protobuf 封套消息中,内部对象数据使用 Unknown 的
420-
`raw` 字段进行记录(有关细节参见 [IDL](##protobuf-encoding-idl))。
427+
`raw` 字段进行记录(有关细节参见 [IDL](#protobuf-encoding-idl))。
421428

422429
<!--
423430
For example:
@@ -989,7 +996,7 @@ of 500 pods at a time, request those chunks as follows:
989996
```
990997

991998
<!--
992-
2. Continue the previous call, retrieving the next set of 500 pods.
999+
1. Continue the previous call, retrieving the next set of 500 pods.
9931000
-->
9941001
2. 继续前面的调用,返回下一组 500 个 Pod:
9951002

@@ -1013,7 +1020,7 @@ of 500 pods at a time, request those chunks as follows:
10131020
```
10141021

10151022
<!--
1016-
3. Continue the previous call, retrieving the last 253 pods.
1023+
1. Continue the previous call, retrieving the last 253 pods.
10171024
-->
10181025
3. 继续前面的调用,返回最后 253 个 Pod:
10191026

@@ -1076,10 +1083,10 @@ collections of different types of resource. Collections have a kind
10761083
named for the resource kind, with `List` appended.
10771084
10781085
When you query the API for a particular type, all items returned by that query are
1079-
of that type.
1080-
For example, when you **list** Services, the collection response
1086+
of that type. For example, when you **list** Services, the collection response
10811087
has `kind` set to
1082-
[`ServiceList`](/docs/reference/kubernetes-api/service-resources/service-v1/#ServiceList); each item in that collection represents a single Service. For example:
1088+
[`ServiceList`](/docs/reference/kubernetes-api/service-resources/service-v1/#ServiceList);
1089+
each item in that collection represents a single Service. For example:
10831090
-->
10841091
## 集合 {#collections}
10851092

@@ -1095,6 +1102,7 @@ has `kind` set to
10951102
```
10961103
GET /api/v1/services
10971104
```
1105+
10981106
```yaml
10991107
{
11001108
"kind": "ServiceList",
@@ -1447,31 +1455,35 @@ validation are `Ignore`, `Warn` (default), and `Strict`.
14471455
从 1.25 开始,当使用可以提交数据的 HTTP 动词(`POST``PUT``PATCH`)时,
14481456
将通过服务器上的校验检测到对象中无法识别或重复的字段。
14491457
校验的级别可以是 `Ignore``Warn`(默认值) 和 `Strict` 之一。
1458+
14501459
<!--
1460+
`Ignore`
14511461
: The API server succeeds in handling the request as it would without the erroneous fields
1452-
being set, dropping all unknown and duplicate fields and giving no indication it
1453-
has done so.
1462+
being set, dropping all unknown and duplicate fields and giving no indication it
1463+
has done so.
14541464
-->
14551465
`Ignore`
14561466
: 使 API 服务器像没有遇到错误字段一样成功处理请求,丢弃所有的未知字段和重复字段,并且不发送丢弃字段的通知。
14571467

14581468
<!--
1469+
`Warn`
14591470
: (Default) The API server succeeds in handling the request, and reports a
1460-
warning to the client. The warning is sent using the `Warning:` response header,
1461-
adding one warning item for each unknown or duplicate field. For more
1462-
information about warnings and the Kubernetes API, see the blog article
1463-
[Warning: Helpful Warnings Ahead](/blog/2020/09/03/warnings/).
1471+
warning to the client. The warning is sent using the `Warning:` response header,
1472+
adding one warning item for each unknown or duplicate field. For more
1473+
information about warnings and the Kubernetes API, see the blog article
1474+
[Warning: Helpful Warnings Ahead](/blog/2020/09/03/warnings/).
14641475
-->
14651476
`Warn`
14661477
:(默认值)使 API 服务器成功处理请求,并向客户端发送告警信息。告警信息通过 `Warning:` 响应头发送,
14671478
并为每个未知字段或重复字段添加一条告警信息。有关告警和相关的 Kubernetes API 的信息,
14681479
可参阅博文[告警:增加实用告警功能](/zh-cn/blog/2020/09/03/warnings/)
14691480

14701481
<!--
1482+
`Strict`
14711483
: The API server rejects the request with a 400 Bad Request error when it
1472-
detects any unknown or duplicate fields. The response message from the API
1473-
server specifies all the unknown or duplicate fields that the API server has
1474-
detected.
1484+
detects any unknown or duplicate fields. The response message from the API
1485+
server specifies all the unknown or duplicate fields that the API server has
1486+
detected.
14751487
-->
14761488
`Strict`
14771489
: API 服务器检测到任何未知字段或重复字段时,拒绝处理请求并返回 400 Bad Request 错误。
@@ -1646,7 +1658,8 @@ request is made. Some of these fields are:
16461658
16471659
* `name`: if `generateName` is set, `name` will have a unique random name
16481660
* `creationTimestamp` / `deletionTimestamp`: records the time of creation/deletion
1649-
* `UID`: [uniquely identifies](/docs/concepts/overview/working-with-objects/names/#uids) the object and is randomly generated (non-deterministic)
1661+
* `UID`: [uniquely identifies](/docs/concepts/overview/working-with-objects/names/#uids)
1662+
the object and is randomly generated (non-deterministic)
16501663
* `resourceVersion`: tracks the persisted version of the object
16511664
* Any field set by a mutating admission controller
16521665
* For the `Service` resource: Ports or IP addresses that the kube-apiserver assigns to Service objects
@@ -1724,7 +1737,8 @@ Kubernetes 使用该 `resourceVersion` 信息,这样 API 服务器可以检测
17241737
<!--
17251738
Instead of sending a PUT request, the client can send an instruction to the API
17261739
server to **patch** an existing resource. A **patch** is typically appropriate
1727-
if the change that the client wants to make isn't conditional on the existing data. Clients that need effective detection of lost updates should consider
1740+
if the change that the client wants to make isn't conditional on the existing data.
1741+
Clients that need effective detection of lost updates should consider
17281742
making their request conditional on the existing `resourceVersion` (either HTTP PUT or HTTP PATCH),
17291743
and then handle any retries that are needed in case there is a conflict.
17301744

@@ -1908,10 +1922,10 @@ A **patch** update is helpful, because:
19081922
<!--
19091923
However:
19101924

1911-
* you need more local (client) logic to build the patch; it helps a lot if you have
1912-
a library implementation of JSON Patch, or even for making a JSON Patch specifically against Kubernetes
1913-
* as the author of client software, you need to be careful when building the patch
1914-
(the HTTP request body) not to drop fields (the order of operations matters)
1925+
* You need more local (client) logic to build the patch; it helps a lot if you have
1926+
a library implementation of JSON Patch, or even for making a JSON Patch specifically against Kubernetes.
1927+
* As the author of client software, you need to be careful when building the patch
1928+
(the HTTP request body) not to drop fields (the order of operations matters).
19151929
-->
19161930
然而:
19171931

@@ -1932,28 +1946,28 @@ Server-Side Apply has some clear benefits:
19321946
* A single round trip: it rarely requires making a `GET` request first.
19331947
* and you can still detect conflicts for unexpected changes
19341948
* you have the option to force override a conflict, if appropriate
1935-
* Client implementations are easy to make
1949+
* Client implementations are easy to make.
19361950
* You get an atomic create-or-update operation without extra effort
1937-
(similar to `UPSERT` in some SQL dialects)
1951+
(similar to `UPSERT` in some SQL dialects).
19381952
-->
19391953
* 仅需一次轮询:通常无需先执行 `GET` 请求。
19401954
* 并且你仍然可以检测到意外更改造成的冲突
19411955
* 合适的时候,你可以选择强制覆盖冲突
1942-
* 客户端实现简单
1956+
* 客户端实现简单
19431957
* 你可以轻松获得原子级别的 create 或 update 操作,无需额外工作
1944-
(类似于某些 SQL 语句中的 `UPSERT`)
1958+
(类似于某些 SQL 语句中的 `UPSERT`)
19451959

19461960
<!--
19471961
However:
19481962

1949-
* Server-Side Apply does not work at all for field changes that depend on a current value of the object
1963+
* Server-Side Apply does not work at all for field changes that depend on a current value of the object.
19501964
* You can only apply updates to objects. Some resources in the Kubernetes HTTP API are
19511965
not objects (they do not have a `.metadata` field), and Server-Side Apply
19521966
is only relevant for Kubernetes objects.
19531967
-->
19541968
然而:
19551969

1956-
* 服务器端应用不适合依赖对象当前值的字段更改
1970+
* 服务器端应用不适合依赖对象当前值的字段更改
19571971
* 你只能更新对象。Kubernetes HTTP API 中的某些资源不是对象(它们没有 `.metadata` 字段),
19581972
并且服务器端应用只能用于 Kubernetes 对象。
19591973

@@ -1986,9 +2000,12 @@ API 客户端只能比较两个资源版本的相等性(这意味着你不能
19862000
Clients find resource versions in resources, including the resources from the response
19872001
stream for a **watch**, or when using **list** to enumerate resources.
19882002

1989-
[v1.meta/ObjectMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#objectmeta-v1-meta) - The `metadata.resourceVersion` of a resource instance identifies the resource version the instance was last modified at.
2003+
[v1.meta/ObjectMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#objectmeta-v1-meta) -
2004+
The `metadata.resourceVersion` of a resource instance identifies the resource version the instance was last modified at.
19902005

1991-
[v1.meta/ListMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#listmeta-v1-meta) - The `metadata.resourceVersion` of a resource collection (the response to a **list**) identifies the resource version at which the collection was constructed.
2006+
[v1.meta/ListMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#listmeta-v1-meta) -
2007+
The `metadata.resourceVersion` of a resource collection (the response to a **list**) identifies the
2008+
resource version at which the collection was constructed.
19922009
-->
19932010
### metadata 中的 `resourceVersion` {#resourceVersion-in-metadata}
19942011

@@ -2080,30 +2097,29 @@ This table explains the behavior of **list** requests with various combinations
20802097
下表解释了具有各种 `resourceVersion` 和 `resourceVersionMatch` 组合的 **list** 请求的行为:
20812098

20822099
<!--
2083-
| resourceVersionMatch param | paging params | resourceVersion not set | resourceVersion="0" | resourceVersion="{value other than 0}" |
2084-
|---------------------------------------|-------------------------------|-----------------------|-------------------------------------------|----------------------------------------|
2085-
| _unset_ | _limit unset_ | Most Recent | Any | Not older than |
2086-
| _unset_ | limit=\<n\>, _continue unset_ | Most Recent | Any | Exact |
2087-
| _unset_ | limit=\<n\>, continue=\<token\> | Continue Token, Exact | Invalid, treated as Continue Token, Exact | Invalid, HTTP `400 Bad Request` |
2088-
| `resourceVersionMatch=Exact` | _limit unset_ | Invalid | Invalid | Exact |
2089-
| `resourceVersionMatch=Exact` | limit=\<n\>, _continue unset_ | Invalid | Invalid | Exact |
2090-
| `resourceVersionMatch=NotOlderThan` | _limit unset_ | Invalid | Any | Not older than |
2091-
| `resourceVersionMatch=NotOlderThan` | limit=\<n\>, _continue unset_ | Invalid | Any | Not older than |
2100+
| resourceVersionMatch param | paging params | resourceVersion not set | resourceVersion="0" | resourceVersion="{value other than 0}" |
2101+
|----------------------------|---------------|-------------------------|---------------------|----------------------------------------|
2102+
| _unset_ | _limit unset_ | Most Recent | Any | Not older than |
2103+
| _unset_ | limit=\<n\>, _continue unset_ | Most Recent | Any | Exact |
2104+
| _unset_ | limit=\<n\>, continue=\<token\>| Continue Token, Exact | Invalid, treated as Continue Token, Exact | Invalid, HTTP `400 Bad Request` |
2105+
| `resourceVersionMatch=Exact` | _limit unset_ | Invalid | Invalid | Exact |
2106+
| `resourceVersionMatch=Exact` | limit=\<n\>, _continue unset_ | Invalid | Invalid | Exact |
2107+
| `resourceVersionMatch=NotOlderThan` | _limit unset_ | Invalid | Any | Not older than |
2108+
| `resourceVersionMatch=NotOlderThan` | limit=\<n\>, _continue unset_ | Invalid | Any | Not older than |
20922109

20932110
{{</* /table */>}}
20942111
-->
2095-
20962112
{{< table caption="list 操作的 resourceVersionMatch 与分页参数" >}}
20972113

2098-
| resourceVersionMatch 参数 | 分页参数 | resourceVersion 未设置 | resourceVersion="0" | resourceVersion="\<非零值\>" |
2099-
|-----------------------------------------|---------------------------------|-------------------------|-----------------------------------------|----------------------------------|
2100-
| **未设置** | **limit 未设置** | 最新版本 | 任意版本 | 不老于指定版本 |
2101-
| **未设置** | limit=\<n\>, **continue 未设置** | 最新版本 | 任意版本 | 精确匹配 |
2102-
| **未设置** | limit=\<n\>, continue=\<token\> | 从 token 开始、精确匹配 | 非法请求,视为从 token 开始、精确匹配 | 非法请求,返回 HTTP `400 Bad Request` |
2103-
| `resourceVersionMatch=Exact` [1] | **limit 未设置** | 非法请求 | 非法请求 | 精确匹配 |
2104-
| `resourceVersionMatch=Exact` [1] | limit=\<n\>, **continue 未设置** | 非法请求 | 非法请求 | 精确匹配 |
2105-
| `resourceVersionMatch=NotOlderThan` [1] | **limit 未设置** | 非法请求 | 任意版本 | 不老于指定版本 |
2106-
| `resourceVersionMatch=NotOlderThan` [1] | limit=\<n\>, **continue 未设置** | 非法请求 | 任意版本 | 不老于指定版本 |
2114+
| resourceVersionMatch 参数 | 分页参数 | resourceVersion 未设置 | resourceVersion="0" | resourceVersion="\<非零值\>" |
2115+
|--------------------------|---------|-----------------------|---------------------|-----------------------------|
2116+
| **未设置** | **limit 未设置** | 最新版本 | 任意版本 | 不老于指定版本 |
2117+
| **未设置** | limit=\<n\>, **continue 未设置** | 最新版本 | 任意版本 | 精确匹配 |
2118+
| **未设置** | limit=\<n\>, continue=\<token\> | 从 token 开始、精确匹配 | 非法请求,视为从 token 开始、精确匹配 | 非法请求,返回 HTTP `400 Bad Request` |
2119+
| `resourceVersionMatch=Exact` [1] | **limit 未设置** | 非法请求 | 非法请求 | 精确匹配 |
2120+
| `resourceVersionMatch=Exact` [1] | limit=\<n\>, **continue 未设置** | 非法请求 | 非法请求 | 精确匹配 |
2121+
| `resourceVersionMatch=NotOlderThan` [1] | **limit 未设置** | 非法请求 | 任意版本 | 不老于指定版本 |
2122+
| `resourceVersionMatch=NotOlderThan` [1] | limit=\<n\>, **continue 未设置** | 非法请求 | 任意版本 | 不老于指定版本 |
21072123

21082124
{{< /table >}}
21092125

0 commit comments

Comments
 (0)