@@ -43,39 +43,222 @@ Kubernetes API 使你可以在 Kubernetes 中查询和操纵 API 对象
43
43
(例如 Pod、Namespace、ConfigMap 和 Event)的状态。
44
44
45
45
<!--
46
- Most operations can be performed through the
47
- [kubectl](/docs/reference/kubectl/) command-line interface or other
48
- command-line tools, such as
49
- [kubeadm](/docs/reference/setup-tools/kubeadm/), which in turn use the
50
- API. However, you can also access the API directly using REST calls.
51
-
52
- Consider using one of the [client libraries](/docs/reference/using-api/client-libraries/)
53
- if you are writing an application using the Kubernetes API.
46
+ Most operations can be performed through the [kubectl](/docs/reference/kubectl/)
47
+ command-line interface or other command-line tools, such as
48
+ [kubeadm](/docs/reference/setup-tools/kubeadm/), which in turn use the API.
49
+ However, you can also access the API directly using REST calls. Kubernetes
50
+ provides a set of [client libraries](/docs/reference/using-api/client-libraries/)
51
+ for those looking to
52
+ write applications using the Kubernetes API.
54
53
-->
55
54
大部分操作都可以通过 [ kubectl] ( /zh-cn/docs/reference/kubectl/ ) 命令行接口或类似
56
55
[ kubeadm] ( /zh-cn/docs/reference/setup-tools/kubeadm/ ) 这类命令行工具来执行,
57
56
这些工具在背后也是调用 API。不过,你也可以使用 REST 调用来访问这些 API。
57
+ Kubernetes 为那些希望使用 Kubernetes API
58
+ 编写应用的开发者提供一组[ 客户端库] ( /zh-cn/docs/reference/using-api/client-libraries/ ) 。
59
+
60
+ <!--
61
+ Each Kubernetes cluster publishes the specification of the APIs that the cluster serves.
62
+ There are two mechanisms that Kubernetes uses to publish these API specifications; both are useful
63
+ to enable automatic interoperability. For example, the `kubectl` tool fetches and caches the API
64
+ specification for enabling command-line completion and other features.
65
+ The two supported mechanisms are as follows:
66
+ -->
67
+ 每个 Kubernetes 集群都会发布集群所使用的 API 规范。
68
+ Kubernetes 使用两种机制来发布这些 API 规范;这两种机制都有助于实现自动互操作。
69
+ 例如,` kubectl ` 工具获取并缓存 API 规范,以实现命令行补全和其他特性。所支持的两种机制如下:
70
+
71
+ <!--
72
+ - [The Discovery API](#discovery-api) provides information about the Kubernetes APIs:
73
+ API names, resources, versions, and supported operations. This is a Kubernetes
74
+ specific term as it is a separate API from the Kubernetes OpenAPI.
75
+ It is intended to be a brief summary of the available resources and it does not
76
+ detail specific schema for the resources. For reference about resource schemas,
77
+ please refer to the OpenAPI document.
78
+ -->
79
+ - [ 发现 API] ( #discovery-api ) 提供有关 Kubernetes API 的信息:API 名称、资源、版本和支持的操作。
80
+ 此 API 是特定于 Kubernetes 的一个术语,因为它是一个独立于 Kubernetes OpenAPI 的 API。
81
+ 其目的是为可用的资源提供简要总结,不详细说明资源的具体模式。有关资源模式的参考,请参阅 OpenAPI 文档。
82
+
83
+ <!--
84
+ - The [Kubernetes OpenAPI Document](#openapi-specification) provides (full)
85
+ [OpenAPI v2.0 and 3.0 schemas](https://www.openapis.org/) for all Kubernetes API
86
+ endpoints.
87
+ The OpenAPI v3 is the preferred method for accessing OpenAPI as it
88
+ provides
89
+ a more comprehensive and accurate view of the API. It includes all the available
90
+ API paths, as well as all resources consumed and produced for every operations
91
+ on every endpoints. It also includes any extensibility components that a cluster supports.
92
+ The data is a complete specification and is significantly larger than that from the
93
+ Discovery API.
94
+ -->
95
+ - [ Kubernetes OpenAPI 文档] ( #openapi-specification ) 为所有 Kubernetes API 端点提供(完整的)
96
+ [ OpenAPI v2.0 和 v3.0 模式] ( https://www.openapis.org/ ) 。OpenAPI v3 是访问 OpenAPI 的首选方法,
97
+ 因为它提供了更全面和准确的 API 视图。其中包括所有可用的 API 路径,以及每个端点上每个操作所接收和生成的所有资源。
98
+ 它还包括集群支持的所有可扩展组件。这些数据是完整的规范,比 Discovery API 提供的规范要大得多。
99
+
100
+ <!--
101
+ ## Discovery API
102
+
103
+ Kubernetes publishes a list of all group versions and resources supported via
104
+ the Discovery API. This includes the following for each resource:
105
+ -->
106
+ ## Discovery API
107
+
108
+ Kubernetes 通过 Discovery API 发布集群所支持的所有组版本和资源列表。对于每个资源,包括以下内容:
109
+
110
+ <!--
111
+ - Name
112
+ - Cluster or namespaced scope
113
+ - Endpoint URL and supported verbs
114
+ - Alternative names
115
+ - Group, version, kind
116
+ -->
117
+ - 名称
118
+ - 集群作用域还是名字空间作用域
119
+ - 端点 URL 和所支持的动词
120
+ - 别名
121
+ - 组、版本、类别
122
+
123
+ <!--
124
+ The API is available both aggregated and unaggregated form. The aggregated
125
+ discovery serves two endpoints while the unaggregated discovery serves a
126
+ separate endpoint for each group version.
127
+ -->
128
+ API 以聚合和非聚合形式提供。聚合的发现提供两个端点,而非聚合的发现为每个组版本提供单独的端点。
129
+
130
+ <!--
131
+ ### Aggregated discovery
132
+ -->
133
+ ### 聚合的发现 {#aggregated-discovery}
134
+
135
+ {{< feature-state state="beta" for_k8s_version="v1.27" >}}
136
+
137
+ <!--
138
+ Kubernetes offers beta support for aggregated discovery, publishing
139
+ all resources supported by a cluster through two endpoints (`/api` and
140
+ `/apis`). Requesting this
141
+ endpoint drastically reduces the number of requests sent to fetch the
142
+ discovery data from the cluster. You can access the data by
143
+ requesting the respective endpoints with an `Accept` header indicating
144
+ the aggregated discovery resource:
145
+ `Accept: application/json;v=v2beta1;g=apidiscovery.k8s.io;as=APIGroupDiscoveryList`.
146
+ -->
147
+ Kubernetes 为聚合的发现提供了 Beta 支持,通过两个端点(` /api ` 和 ` /apis ` )发布集群所支持的所有资源。
148
+ 请求这个端点会大大减少从集群获取发现数据时发送的请求数量。你可以通过带有
149
+ ` Accept ` 头(` Accept: application/json;v=v2beta1;g=apidiscovery.k8s.io;as=APIGroupDiscoveryList ` )
150
+ 的请求发送到不同端点,来指明聚合发现的资源。
151
+
152
+ <!--
153
+ Without indicating the resource type using the `Accept` header, the default
154
+ response for the `/api` and `/apis` endpoint is an unaggregated discovery
155
+ document.
156
+ -->
157
+ 如果没有使用 ` Accept ` 头指示资源类型,对于 ` /api ` 和 ` /apis ` 端点的默认响应将是一个非聚合的发现文档。
158
+
159
+ <!--
160
+ The [discovery document](https://github.com/kubernetes/kubernetes/blob/release-v{{< skew currentVersion >}}/api/discovery/aggregated_v2beta1.json)
161
+ for the built-in resources can be found in the Kubernetes GitHub repository.
162
+ This Github document can be used as a reference of the base set of the available resources
163
+ if a Kubernetes cluster is not available to query.
164
+
165
+ The endpoint also supports ETag and protobuf encoding.
166
+ -->
167
+ 内置资源的[ 发现文档] (https://github.com/kubernetes/kubernetes/blob/release-v{{ < skew currentVersion >}}/api/discovery/aggregated_v2beta1.json)可以在
168
+ Kubernetes GitHub 代码仓库中找到。如果手头没有 Kubernetes 集群可供查询,
169
+ 此 Github 文档可用作可用资源的基础集合的参考。端点还支持 ETag 和 protobuf 编码。
170
+
171
+ <!--
172
+ ### Unaggregated discovery
173
+
174
+ Without discovery aggregation, discovery is published in levels, with the root
175
+ endpoints publishing discovery information for downstream documents.
176
+
177
+ A list of all group versions supported by a cluster is published at
178
+ the `/api` and `/apis` endpoints. Example:
179
+ -->
180
+ ### 非聚合的发现 {#unaggregated-discovery}
181
+
182
+ 在不使用聚合发现的情况下,发现 API 以不同级别发布,同时根端点为下游文档发布发现信息。
183
+
184
+ 集群支持的所有组版本列表发布在 ` /api ` 和 ` /apis ` 端点。例如:
185
+
186
+ ```
187
+ {
188
+ "kind": "APIGroupList",
189
+ "apiVersion": "v1",
190
+ "groups": [
191
+ {
192
+ "name": "apiregistration.k8s.io",
193
+ "versions": [
194
+ {
195
+ "groupVersion": "apiregistration.k8s.io/v1",
196
+ "version": "v1"
197
+ }
198
+ ],
199
+ "preferredVersion": {
200
+ "groupVersion": "apiregistration.k8s.io/v1",
201
+ "version": "v1"
202
+ }
203
+ },
204
+ {
205
+ "name": "apps",
206
+ "versions": [
207
+ {
208
+ "groupVersion": "apps/v1",
209
+ "version": "v1"
210
+ }
211
+ ],
212
+ "preferredVersion": {
213
+ "groupVersion": "apps/v1",
214
+ "version": "v1"
215
+ }
216
+ },
217
+ ...
218
+ }
219
+ ```
58
220
59
- 如果你正在编写程序来访问 Kubernetes API,
60
- 可以考虑使用[ 客户端库] ( /zh-cn/docs/reference/using-api/client-libraries/ ) 之一。
221
+ <!--
222
+ Additional requests are needed to obtain the discovery document for each group version at
223
+ `/apis/<group>/<version>` (for example:
224
+ `/apis/rbac.authorization.k8s.io/v1alpha1`), which advertises the list of
225
+ resources served under a particular group version. These endpoints are used by
226
+ kubectl to fetch the list of resources supported by a cluster.
227
+ -->
228
+ 用户需要发出额外的请求才能在 ` /apis/<group>/<version> ` (例如 ` /apis/rbac.authorization.k8s.io/v1alpha1 ` )
229
+ 获取每个组版本的发现文档。这些发现文档会公布在特定组版本下所提供的资源列表。
230
+ kubectl 使用这些端点来获取某集群所支持的资源列表。
61
231
62
232
<!-- body -->
63
233
234
+ <a id =" #api-specification " />
235
+
64
236
<!--
65
- ## OpenAPI specification {#api-specification}
237
+ ## OpenAPI interface definition
66
238
67
- Complete API details are documented using [OpenAPI](https://www.openapis.org/).
239
+ For details about the OpenAPI specifications, see the [OpenAPI documentation ](https://www.openapis.org/).
68
240
241
+ Kubernetes serves both OpenAPI v2.0 and OpenAPI v3.0. OpenAPI v3 is the
242
+ preferred method of accessing the OpenAPI because it offers a more comprehensive
243
+ (lossless) representation of Kubernetes resources. Due to limitations of OpenAPI
244
+ version 2, certain fields are dropped from the published OpenAPI including but not
245
+ limited to `default`, `nullable`, `oneOf`.
246
+ -->
247
+ ## OpenAPI 接口定义 {#openapi-interface-definition}
248
+
249
+ 有关 OpenAPI 规范的细节,参阅 [ OpenAPI 文档] ( https://www.openapis.org/ ) 。
250
+
251
+ Kubernetes 同时提供 OpenAPI v2.0 和 OpenAPI v3.0。OpenAPI v3 是访问 OpenAPI 的首选方法,
252
+ 因为它提供了对 Kubernetes 资源更全面(无损)的表示。由于 OpenAPI v2 的限制,
253
+ 所公布的 OpenAPI 中会丢弃掉一些字段,包括但不限于 ` default ` 、` nullable ` 、` oneOf ` 。
254
+
255
+ <!--
69
256
### OpenAPI V2
70
257
71
258
The Kubernetes API server serves an aggregated OpenAPI v2 spec via the
72
259
`/openapi/v2` endpoint. You can request the response format using
73
260
request headers as follows:
74
261
-->
75
- ## OpenAPI 规范 {#api-specification}
76
-
77
- 完整的 API 细节是用 [ OpenAPI] ( https://www.openapis.org/ ) 来表述的。
78
-
79
262
### OpenAPI v2
80
263
81
264
Kubernetes API 服务器通过 ` /openapi/v2 ` 端点提供聚合的 OpenAPI v2 规范。
@@ -144,21 +327,9 @@ Kubernetes API 服务器通过 `/openapi/v2` 端点提供聚合的 OpenAPI v2
144
327
</tbody >
145
328
</table >
146
329
147
- <!--
148
- Kubernetes implements an alternative Protobuf based serialization format that
149
- is primarily intended for intra-cluster communication. For more information
150
- about this format, see the [Kubernetes Protobuf serialization](https://git.k8s.io/design-proposals-archive/api-machinery/protobuf.md) design proposal and the
151
- Interface Definition Language (IDL) files for each schema located in the Go
152
- packages that define the API objects.
153
- -->
154
- Kubernetes 为 API 实现了一种基于 Protobuf 的序列化格式,主要用于集群内部通信。
155
- 关于此格式的详细信息,可参考
156
- [ Kubernetes Protobuf 序列化] ( https://git.k8s.io/design-proposals-archive/api-machinery/protobuf.md ) 设计提案。
157
- 每种模式对应的接口描述语言(IDL)位于定义 API 对象的 Go 包中。
158
-
159
330
### OpenAPI v3
160
331
161
- {{< feature-state state="stable" for_k8s_version="v1.27 " >}}
332
+ {{< feature-state feature_gate_name="OpenAPIV3 " >}}
162
333
163
334
<!--
164
335
Kubernetes supports publishing a description of its APIs as OpenAPI v3.
@@ -245,9 +416,34 @@ Kubernetes API 服务器会在端点 `/openapi/v3/apis/<group>/<version>?hash=<h
245
416
</table >
246
417
247
418
<!--
248
- A Golang implementation to fetch the OpenAPI V3 is provided in the package `k8s.io/client-go/openapi3`.
419
+ A Golang implementation to fetch the OpenAPI V3 is provided in the package
420
+ [`k8s.io/client-go/openapi3`](https://pkg.go.dev/k8s.io/client-go/openapi3).
421
+
422
+ Kubernetes {{< skew currentVersion >}} publishes
423
+ OpenAPI v2.0 and v3.0; there are no plans to support 3.1 in the near future.
424
+ -->
425
+ [ ` k8s.io/client-go/openapi3 ` ] ( https://pkg.go.dev/k8s.io/client-go/openapi3 )
426
+ 包中提供了获取 OpenAPI v3 的 Golang 实现。
427
+
428
+ Kubernetes {{< skew currentVersion >}} 发布了 OpenAPI v2.0 和 v3.0;
429
+ 近期没有支持 v3.1 的计划。
430
+
431
+ <!--
432
+ ### Protobuf serialization
433
+
434
+ Kubernetes implements an alternative Protobuf based serialization format that
435
+ is primarily intended for intra-cluster communication. For more information
436
+ about this format, see the [Kubernetes Protobuf serialization](https://git.k8s.io/design-proposals-archive/api-machinery/protobuf.md)
437
+ design proposal and the
438
+ Interface Definition Language (IDL) files for each schema located in the Go
439
+ packages that define the API objects.
249
440
-->
250
- ` k8s.io/client-go/openapi3 ` 包中提供了获取 OpenAPI v3 的 Golang 实现。
441
+ ### Protobuf 序列化 {#protobuf-serialization}
442
+
443
+ Kubernetes 为 API 实现了一种基于 Protobuf 的序列化格式,主要用于集群内部通信。
444
+ 关于此格式的详细信息,可参考
445
+ [ Kubernetes Protobuf 序列化] ( https://git.k8s.io/design-proposals-archive/api-machinery/protobuf.md ) 设计提案。
446
+ 每种模式对应的接口描述语言(IDL)位于定义 API 对象的 Go 包中。
251
447
252
448
<!--
253
449
## Persistence
0 commit comments