Skip to content

Commit 5fabc13

Browse files
authored
Merge pull request #25130 from tengqm/zh-sync-crd
[zh] sync tasks/extend-kubernetes/custom-resources/custom-resource-de…
2 parents c37cac5 + dafaec2 commit 5fabc13

File tree

1 file changed

+79
-86
lines changed

1 file changed

+79
-86
lines changed

content/zh/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md

Lines changed: 79 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ weight: 20
1818
-->
1919

2020
<!-- overview -->
21-
本页展示如何使用
21+
<!--
22+
This page shows how to install a
23+
[custom resource](/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
24+
into the Kubernetes API by creating a
2225
[CustomResourceDefinition](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#customresourcedefinition-v1-apiextensions-k8s-io).
26+
-->
27+
本页展示如何使用
28+
[CustomResourceDefinition](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#customresourcedefinition-v1-apiextensions-k8s-io)
2329
24-
[自定义资源(Custom Resource)](/zh/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
25-
安装到 Kubernetes API。
30+
[定制资源(Custom Resource)](/zh/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
31+
安装到 Kubernetes API
2632

2733
## {{% heading "prerequisites" %}}
2834

@@ -256,7 +262,7 @@ kubectl get ct -o yaml
256262

257263
<!--
258264
You should see that it contains the custom `cronSpec` and `image` fields
259-
from the yaml you used to create it:
265+
from the YAML you used to create it:
260266
-->
261267
你可以看到输出中包含了你创建定制对象时在 YAML 文件中指定的定制字段 `cronSpec`
262268
`image`
@@ -284,7 +290,7 @@ metadata:
284290
<!--
285291
## Delete a CustomResourceDefinition
286292
287-
When you delete a CustomResourceDefinition, the server will uninstall the RESTful API endpoint
293+
When you delete a CustomResourceDefinition, the server will uninstall the RESTful API endpoint
288294
and delete all custom objects stored in it.
289295
-->
290296
## 删除 CustomResourceDefinition {#delete-a-customresourcedefinition}
@@ -309,25 +315,30 @@ If you later recreate the same CustomResourceDefinition, it will start out empty
309315
<!--
310316
## Specifying a structural schema
311317
312-
CustomResources store structured data in custom fiels (alongside the built-in fields `apiVersion`, `kind` and `metadata`, which the API server validates implicitly). With [OpenAPI v3.0 validation](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation) a schema can be specified, which is validated during creation and updates, compare below for details and limits of such a schema.
318+
CustomResources store structured data in custom fiels (alongside the built-in
319+
fields `apiVersion`, `kind` and `metadata`, which the API server validates
320+
implicitly). With [OpenAPI v3.0 validation](#validation) a schema can be
321+
specified, which is validated during creation and updates, compare below for
322+
details and limits of such a schema.
313323
314-
With `apiextensions.k8s.io/v1` the definition of a structural schema is mandatory for CustomResourceDefinitions (in the beta version of CustomResourceDefinition, structural schemas were optional).
324+
With `apiextensions.k8s.io/v1` the definition of a structural schema is
325+
mandatory for CustomResourceDefinitions. In the beta version of
326+
CustomResourceDefinition, structural schemas were optional.
315327
-->
316328
## 设置结构化的模式 {#specifying-a-structural-schema}
317329

318330
CustomResource 对象在定制字段中保存结构化的数据,这些字段和内置的字段
319331
`apiVersion``kind``metadata` 等一起存储,不过内置的字段都会被 API
320-
服务器隐式完成合法性检查。
321-
有了 [OpenAPI v3.0 检查](#validation)
332+
服务器隐式完成合法性检查。有了 [OpenAPI v3.0 检查](#validation)
322333
能力之后,你可以设置一个模式(Schema),在创建和更新定制对象时,这一模式会被用来
323334
对对象内容进行合法性检查。参阅下文了解这类模式的细节和局限性。
324335

325336
`apiextensions.k8s.io/v1` 版本中,CustomResourceDefinition 的这一结构化模式
326-
定义是必需的(在 CustomResourceDefinition 的 beta
327-
版本中,结构化模式定义是可选的
337+
定义是必需的
338+
在 CustomResourceDefinition 的 beta 版本中,结构化模式定义是可选的。
328339

329340
<!--
330-
A structural schema is an [OpenAPI v3.0 validation schema](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation) which:
341+
A structural schema is an [OpenAPI v3.0 validation schema](#validation) which:
331342
332343
1. specifies a non-empty type (via `type` in OpenAPI) for the root, for each specified field of an object node (via `properties` or `additionalProperties` in OpenAPI) and for each item in an array node (via `items` in OpenAPI), with the exception of:
333344
* a node with `x-kubernetes-int-or-string: true`
@@ -445,7 +456,7 @@ is not a structural schema because of the following violations:
445456
* `bar` inside of `anyOf` is not specified outside (rule 2).
446457
* `bar`'s `type` is within `anyOf` (rule 3).
447458
* the description is set within `anyOf` (rule 3).
448-
* `metadata.finalizer` might not be restricted (rule 4).
459+
* `metadata.finalizers` might not be restricted (rule 4).
449460
-->
450461
不是一个结构化的模式,因为其中存在以下违例:
451462

@@ -454,7 +465,7 @@ is not a structural schema because of the following violations:
454465
* `anyOf` 中的 `bar` 未在外部指定(规则 2)
455466
* `bar` 的 `type` 位于 `anyOf` 中(规则 3)
456467
* `anyOf` 中设置了 `description` (规则 3)
457-
* `metadata.finalizer` 不可以被限制 (规则 4)
468+
* `metadata.finalizers` 不可以被限制 (规则 4)
458469

459470
<!--
460471
In contrast, the following, corresponding schema is structural:
@@ -510,7 +521,7 @@ CRDs converted from `apiextensions.k8s.io/v1beta1` to
510521

511522
For migrated CustomResourceDefinitions where `spec.preserveUnknownFields` is
512523
set, pruning is _not_ enabled and you can store arbitrary data. For best
513-
compatibility, you should update customer resources to meet an OpenAPI schema,
524+
compatibility, you should update your custom resources to meet an OpenAPI schema,
514525
and you should set `spec.preserveUnknownFields` true for the
515526
CustomResourceDefinition itself.
516527
-->
@@ -577,7 +588,7 @@ Notice that the field `someRandomField` was pruned.
577588

578589
<!--
579590
This example turned off client-side validation to demonstrate the API server's behavior, by adding the `--validate=false` command line option.
580-
Because the [OpenAPI validation schemas are also published](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#publish-validation-schema-in-openapi-v2)
591+
Because the [OpenAPI validation schemas are also published](#publish-validation-schema-in-openapi-v2)
581592
to clients, `kubectl` also checks for unknown fields and rejects those objects well before they would be sent to the API server.
582593
-->
583594
本例中通过 `--validate=false` 命令行选项 关闭了客户端的合法性检查以展示 API 服务器的行为,
@@ -588,13 +599,13 @@ to clients, `kubectl` also checks for unknown fields and rejects those objects w
588599
<!--
589600
#### Controlling pruning
590601

591-
By default, all unspecified fields for a custom resource, across all versions, are pruned. It is possible though to opt-out of that for specifc sub-trees fof fields by adding `x-kubernetes-preserve-unknown-fields: true` in the [structural OpenAPI v3 validation schema](#specifying-a-structural-schema).
602+
By default, all unspecified fields for a custom resource, across all versions, are pruned. It is possible though to opt-out of that for specifc sub-trees fof fields by adding `x-kubernetes-preserve-unknown-fields: true` in the [structural OpenAPI v3 validation schema](#specifying-a-structural-schema).
592603
For example:
593604
-->
594605
#### 控制剪裁 {#controlling-pruning}
595606

596607
默认情况下,定制资源的所有版本中的所有未规定的字段都会被剪裁掉。
597-
通过在 [结构化 OpenAPI v3 合法性检查模式定](#specifying-a-structural-schema)
608+
通过在结构化的 OpenAPI v3 [检查模式定义](#specifying-a-structural-schema)
598609
中为特定字段的子树添加 `x-kubernetes-preserve-unknown-fields: true` 属性,可以
599610
选择不对其执行剪裁操作。
600611
例如:
@@ -731,7 +742,7 @@ allOf:
731742
<!--
732743
With one of those specification, both an integer and a string validate.
733744

734-
In [Validation Schema Publishing](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#publish-validation-schema-in-openapi-v2),
745+
In [Validation Schema Publishing](#publish-validation-schema-in-openapi-v2),
735746
`x-kubernetes-int-or-string: true` is unfolded to one of the two patterns shown above.
736747
-->
737748
在以上两种规约中,整数值和字符串值都会被认为是合法的。
@@ -832,52 +843,51 @@ apiVersion: "stable.example.com/v1"
832843
kind: CronTab
833844
metadata:
834845
finalizers:
835-
- finalizer.stable.example.com
846+
- stable.example.com/finalizer
836847
```
837848

838849
<!--
839-
Finalizers are arbitrary string values, that when present ensure that a hard delete
840-
of a resource is not possible while they exist.
850+
Identifiers of custom finalizers consist of a domain name, a forward slash and the name of
851+
the finalizer. Any controller can add a finalizer to any object's list of finalizers.
841852

842853
The first delete request on an object with finalizers sets a value for the
843854
`metadata.deletionTimestamp` field but does not delete it. Once this value is set,
844-
entries in the `finalizer` list can only be removed.
855+
entries in the `finalizers` list can only be removed. While any finalizers remain it is also
856+
impossible to force the deletion of an object.
845857

846-
When the `metadata.deletionTimestamp` field is set, controllers watching the object
847-
execute any finalizers they handle, by polling update requests for that
848-
object. When all finalizers have been executed, the resource is deleted.
858+
When the `metadata.deletionTimestamp` field is set, controllers watching the object execute any
859+
finalizers they handle and remove the finalizer from the list after they are done. It is the
860+
responsibility of each controller to remove its finalizer from the list.
849861
-->
850-
Finalizer 可以取任意的字符串值。当资源上存在 Finalizer 时,无法硬性删除该资源。
862+
自定义 Finalizer 的标识符包含一个域名、一个正向斜线和 finalizer 的名称。
863+
任何控制器都可以在任何对象的 finalizer 列表中添加新的 finalizer。
851864

852865
对带有 Finalizer 的对象的第一个删除请求会为其 `metadata.deletionTimestamp`
853-
设置一个值,但不会真的删除对象。一旦此值被设置,`finalizers`
854-
列表中的表项只能被移除
866+
设置一个值,但不会真的删除对象。一旦此值被设置,`finalizers` 列表中的表项
867+
只能被移除。在列表中仍然包含 finalizer 时,无法强制删除对应的对象
855868

856-
当 `metadata.deletionTimestamp` 字段被设置时,负责监测该对象的各个控制器会通过
857-
轮询对该对象的更新请求来执行它们所要处理的所有 Finalizer
858-
当所有 Finalizer 都被执行过,资源被删除
869+
当 `metadata.deletionTimestamp` 字段被设置时,监视该对象的各个控制器会
870+
执行它们所能处理的 finalizer,并在完成处理之后将其从列表中移除
871+
每个控制器负责将其 finalizer 从列表中删除
859872

860873
<!--
861-
The value of `metadata.deletionGracePeriodSeconds` controls the interval between
862-
polling updates.
863-
864-
It is the responsibility of each controller to remove its finalizer from the list.
874+
The value of `metadata.deletionGracePeriodSeconds` controls the interval between polling updates.
865875

866-
Kubernetes only finally deletes the object if the list of finalizers is empty,
867-
meaning all finalizers have been executed.
876+
Once the list of finalizers is empty, meaning all finalizers have been executed, the resource is
877+
deleted by Kubernetes.
868878
-->
869879
`metadata.deletionGracePeriodSeconds` 的取值控制对更新的轮询周期。
870880

871-
每个控制器要负责将其 Finalizer 从列表中去除。
872-
873-
只有 `finalizers` 列表为空时,意味着所有 Finalizer 都被执行过之后,
874-
Kubernetes 才会最终删除对象,
881+
一旦 finalizers 列表为空时,就意味着所有 finalizer 都被执行过,
882+
Kubernetes 会最终删除该资源,
875883

876884
<!--
877885
### Validation
878886

879887
Custom resources are validated via
880-
[OpenAPI v3 schemas](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject) and you can add additional validation using [admission webhooks](/docs/reference/access-authn-authz/admission-controllers/#validatingadmissionwebhook).
888+
[OpenAPI v3 schemas](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject)
889+
and you can add additional validation using
890+
[admission webhooks](/docs/reference/access-authn-authz/admission-controllers/#validatingadmissionwebhook).
881891
-->
882892
### 合法性检查 {#validation}
883893

@@ -901,8 +911,8 @@ Additionally, the following restrictions are applied to the schema:
901911
- `writeOnly`,
902912
- `xml`,
903913
- `$ref`.
904-
- The field `uniqueItems` cannot be set to _true_.
905-
- The field `additionalProperties` cannot be set to _false_.
914+
- The field `uniqueItems` cannot be set to `true`.
915+
- The field `additionalProperties` cannot be set to `false`.
906916
- The field `additionalProperties` is mutually exclusive with `properties`.
907917
-->
908918
此外,对模式定义存在以下限制:
@@ -923,22 +933,26 @@ Additionally, the following restrictions are applied to the schema:
923933
- 字段 `additionalProperties` 与 `properties` 互斥,不可同时使用
924934

925935
<!--
926-
These fields can only be set with specific features enabled:
927-
928-
- `default`: can be set for `apiextensions.k8s.io/v1` CustomResourceDefinitions. Defaulting is in GA since 1.17 (beta since 1.16 with the `CustomResourceDefaulting` feature gate to be enabled, which is the case automatically for many clusters for beta features). Compare [Validation Schema Defaulting](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting).
936+
The `default` field can be set when the [Defaulting feature](#defaulting) is enabled,
937+
which is the case with `apiextensions.k8s.io/v1` CustomResourceDefinitions.
938+
Defaulting is in GA since 1.17 (beta since 1.16 with the `CustomResourceDefaulting`
939+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
940+
enabled, which is the case automatically for many clusters for beta features).
929941
-->
930-
以下字段仅可用于某些条件被满足的情况下:
931942

932-
- `default`:可在 `apiextensions.k8s.io/v1` API 组中的 CustomResourceDefinition 的
933-
模式定义中使用。设置默认值的功能特性从 1.17 开始正式发布。该特性在 1.16 版本中处于
934-
Beta 状态,要求 `CustomResourceDefaulting` 特性门控被启用。对于大多数集群而言,
935-
Beta 状态的特性门控默认都是自动启用的。
936-
你可以将此字段的作用与[合法性检查模式的默认值设定](#defaulting)相比较。
943+
当[设置默认值特性](#defaulting)被启用时,可以设置字段 `default`。
944+
就 `apiextensions.k8s.io/v1` 组的 CustomResourceDefinitions,这一条件是满足的。
945+
设置默认值的功能特性从 1.17 开始正式发布。该特性在 1.16 版本中处于
946+
Beta 状态,要求 `CustomResourceDefaulting`
947+
[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
948+
被启用。对于大多数集群而言,Beta 状态的特性门控默认都是自动启用的。
937949

938-
{{< note >}}
950+
<!--
951+
Refer to the [structural schemas](#specifying-a-structural-schema) section for other
952+
restrictions and CustomResourceDefinition features.
953+
-->
939954
关于对某些 CustomResourceDefinition 特性所必需的限制,可参见
940-
[结构化的模式定义](#specifying-a-structural-schema)。
941-
{{< /note >}}
955+
[结构化的模式定义](#specifying-a-structural-schema)小节。
942956

943957
<!--
944958
The schema is defined in the CustomResourceDefinition. In the following example, the
@@ -1203,7 +1217,7 @@ Default values for `metadata` fields of `x-kubernetes-embedded-resources: true`
12031217
<!--
12041218
### Publish Validation Schema in OpenAPI v2
12051219

1206-
CustomResourceDefinition [OpenAPI v3 validation schemas](#validation) which are [structural](#specifying-a-structural-schema) and [enable pruning](#preserving-unknown-fields) are published as part of the [OpenAPI v2 spec](/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions) from Kubernetes API server.
1220+
CustomResourceDefinition [OpenAPI v3 validation schemas](#validation) which are [structural](#specifying-a-structural-schema) and [enable pruning](#field-pruning) are published as part of the [OpenAPI v2 spec](/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions) from Kubernetes API server.
12071221

12081222
The [kubectl](/docs/reference/kubectl/overview) command-line tool consumes the published schema to perform client-side validation (`kubectl create` and `kubectl apply`), schema explanation (`kubectl explain`) on custom resources. The published schema can be consumed for other purposes as well, like client generation or documentation.
12091223
-->
@@ -1356,15 +1370,15 @@ The `NAME` column is implicit and does not need to be defined in the CustomResou
13561370
<!--
13571371
#### Priority
13581372
1359-
Each column includes a `priority` field for each column. Currently, the priority
1373+
Each column includes a `priority` field. Currently, the priority
13601374
differentiates between columns shown in standard view or wide view (using the `-o wide` flag).
13611375
13621376
- Columns with priority `0` are shown in standard view.
13631377
- Columns with priority greater than `0` are shown only in wide view.
13641378
-->
13651379
#### 优先级 {#priority}
13661380
1367-
每个列都包含一个 `priority` 字段。当前,优先级用来区分标准视图(Standard
1381+
每个列都包含一个 `priority`(优先级)字段。当前,优先级用来区分标准视图(Standard
13681382
View)和宽视图(Wide View)(使用 `-o wide` 标志)中显示的列:
13691383
13701384
- 优先级为 `0` 的列会在标准视图中显示。
@@ -1378,7 +1392,7 @@ A column's `type` field can be any of the following (compare [OpenAPI v3 data ty
13781392
- `integer` – non-floating-point numbers
13791393
- `number` – floating point numbers
13801394
- `string` – strings
1381-
- `boolean` – true or false
1395+
- `boolean` – `true` or `false`
13821396
- `date` – rendered differentially as time since this timestamp.
13831397
-->
13841398
#### 类型 {#type}
@@ -1462,27 +1476,6 @@ When the status subresource is enabled, the `/status` subresource for the custom
14621476
的取值都会增加。
14631477
<!--
14641478
- Only the following constructs are allowed at the root of the CRD OpenAPI validation schema:
1465-
1466-
- Description
1467-
- Example
1468-
- ExclusiveMaximum
1469-
- ExclusiveMinimum
1470-
- ExternalDocs
1471-
- Format
1472-
- Items
1473-
- Maximum
1474-
- MaxItems
1475-
- MaxLength
1476-
- Minimum
1477-
- MinItems
1478-
- MinLength
1479-
- MultipleOf
1480-
- Pattern
1481-
- Properties
1482-
- Required
1483-
- Title
1484-
- Type
1485-
- UniqueItems
14861479
-->
14871480
- 在 CRD OpenAPI 合法性检查模式定义的根节点,只允许存在以下结构:
14881481
@@ -1503,7 +1496,7 @@ When the status subresource is enabled, the `/status` subresource for the custom
15031496
- `pattern`
15041497
- `properties`
15051498
- `required`
1506-
-` title`
1499+
- `title`
15071500
- `type`
15081501
- `uniqueItems`
15091502
@@ -1513,7 +1506,7 @@ When the status subresource is enabled, the `/status` subresource for the custom
15131506
When the scale subresource is enabled, the `/scale` subresource for the custom resource is exposed.
15141507
The `autoscaling/v1.Scale` object is sent as the payload for `/scale`.
15151508
1516-
To enable the scale subresource, the following values are defined in the CustomResourceDefinition.
1509+
To enable the scale subresource, the following fields are defined in the CustomResourceDefinition.
15171510
-->
15181511
#### Scale 子资源 {#scale-subresource}
15191512
@@ -1527,7 +1520,7 @@ To enable the scale subresource, the following values are defined in the CustomR
15271520
15281521
- It is a required value.
15291522
- Only JSONPaths under `.spec` and with the dot notation are allowed.
1530-
- If there is no value under the `SpecReplicasPath` in the custom resource,
1523+
- If there is no value under the `specReplicasPath` in the custom resource,
15311524
the `/scale` subresource will return an error on GET.
15321525
-->
15331526
- `specReplicasPath` 指定定制资源内与 `scale.spec.replicas` 对应的 JSON 路径。
@@ -1813,7 +1806,7 @@ kubectl apply -f my-crontab.yaml
18131806
```
18141807

18151808
<!--
1816-
You can specify the category using `kubectl get`:
1809+
You can specify the category when using `kubectl get`:
18171810
-->
18181811
你可以在使用 `kubectl get` 时指定分类:
18191812

0 commit comments

Comments
 (0)