Skip to content

Commit 6f5cca9

Browse files
authored
Merge pull request #49051 from my-git9/pp-14916
[zh-cn]sync custom-resource-definitions.md
2 parents 3a851a8 + 1eab8cd commit 6f5cca9

File tree

1 file changed

+74
-31
lines changed

1 file changed

+74
-31
lines changed

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

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ metadata:
118118
# 名字必需与下面的 spec 字段匹配,并且格式为 '<名称的复数形式>.<组名>'
119119
name: crontabs.stable.example.com
120120
spec:
121-
# 组名称,用于 REST API: /apis/<组>/<版本>
121+
# 组名称,用于 REST API/apis/<组>/<版本>
122122
group: stable.example.com
123123
# 列举此 CustomResourceDefinition 所支持的版本
124124
versions:
@@ -182,12 +182,11 @@ You can watch the `Established` condition of your CustomResourceDefinition
182182
to be true or watch the discovery information of the API server for your
183183
resource to show up.
184184
-->
185-
此端点 URL 自此可以用来创建和管理定制对象。对象的 `kind` 将是来自你上面创建时
186-
所用的 spec 中指定的 `CronTab`
185+
此端点 URL 自此可以用来创建和管理定制对象。对象的 `kind`
186+
将是来自你上面创建时所用的规约中指定的 `CronTab`
187187

188188
创建端点的操作可能需要几秒钟。你可以监测你的 CustomResourceDefinition 的
189-
`Established` 状况变为 true,或者监测 API 服务器的发现信息等待你的资源出现在
190-
那里。
189+
`Established` 状况变为 true,或者监测 API 服务器的发现信息等待你的资源出现在那里。
191190

192191
<!--
193192
## Create custom objects
@@ -254,8 +253,8 @@ the singular or plural forms defined in the CRD, as well as any short names.
254253
255254
You can also view the raw YAML data:
256255
-->
257-
使用 kubectl 时,资源名称是大小写不敏感的,而且你既可以使用 CRD 中所定义的单数
258-
形式或复数形式,也可以使用其短名称:
256+
使用 kubectl 时,资源名称是大小写不敏感的,而且你既可以使用 CRD
257+
中所定义的单数形式或复数形式,也可以使用其短名称:
259258

260259
```shell
261260
kubectl get ct -o yaml
@@ -335,12 +334,12 @@ CustomResourceDefinition, the structural schema was optional.
335334

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

342-
`apiextensions.k8s.io/v1` 版本中,CustomResourceDefinition 的这一结构化模式
343-
定义是必需的
341+
`apiextensions.k8s.io/v1` 版本中,CustomResourceDefinition
342+
的这一结构化模式定义是必需的
344343
在 CustomResourceDefinition 的 beta 版本中,结构化模式定义是可选的。
345344

346345
<!--
@@ -375,7 +374,7 @@ A structural schema is an [OpenAPI v3.0 validation schema](#validation) which:
375374
<!--
376375
Non-structural example 1:
377376
-->
378-
非结构化的例 1:
377+
非结构化的例 1
379378

380379
```none
381380
allOf:
@@ -616,8 +615,8 @@ to clients, `kubectl` also checks for unknown fields and rejects those objects w
616615
would be sent to the API server.
617616
-->
618617
本例中通过 `--validate=false` 命令行选项 关闭了客户端的合法性检查以展示 API 服务器的行为,
619-
因为 [OpenAPI 合法性检查模式也会发布到](#publish-validation-schema-in-openapi)
620-
客户端,`kubectl` 也会检查未知的字段并在对象被发送到 API
618+
因为 [OpenAPI 合法性检查模式也会发布到](#publish-validation-schema-in-openapi)客户端,
619+
`kubectl` 也会检查未知的字段并在对象被发送到 API
621620
服务器之前就拒绝它们。
622621

623622
<!--
@@ -632,8 +631,8 @@ For example:
632631
#### 控制剪裁 {#controlling-pruning}
633632

634633
默认情况下,定制资源的所有版本中的所有未规定的字段都会被剪裁掉。
635-
通过在结构化的 OpenAPI v3 [检查模式定义](#specifying-a-structural-schema)
636-
中为特定字段的子树添加 `x-kubernetes-preserve-unknown-fields: true` 属性,
634+
通过在结构化的 OpenAPI v3 [检查模式定义](#specifying-a-structural-schema)中为特定字段的子树添加
635+
`x-kubernetes-preserve-unknown-fields: true` 属性,
637636
可以选择不对其执行剪裁操作。
638637

639638
例如:
@@ -755,6 +754,9 @@ anyOf:
755754
...
756755
```
757756

757+
<!--
758+
and
759+
-->
758760
759761

760762
```none
@@ -973,7 +975,7 @@ The `x-kubernetes-validations` extension can be used to validate custom resource
973975
当[验证规则特性](#validation-rules)被启用并且 CustomResourceDefinition
974976
模式是一个[结构化的模式定义](#specifying-a-structural-schema)时,
975977
`x-kubernetes-validations`
976-
扩展可以使用[通用表达式语言 (CEL)](https://github.com/google/cel-spec)表达式来验证定制资源。
978+
扩展可以使用[通用表达式语言CEL](https://github.com/google/cel-spec)表达式来验证定制资源。
977979

978980
<!--
979981
Refer to the [structural schemas](#specifying-a-structural-schema) section for other
@@ -1296,7 +1298,7 @@ rules are supported.
12961298
<!--
12971299
For example:
12981300
-->
1299-
例如:
1301+
例如
13001302

13011303
```none
13021304
...
@@ -1327,7 +1329,7 @@ For example:
13271329
<!--
13281330
will reject a request to create this custom resource:
13291331
-->
1330-
将拒绝创建这个定制资源的请求:
1332+
将拒绝创建这个定制资源的请求
13311333

13321334
```yaml
13331335
apiVersion: "stable.example.com/v1"
@@ -2732,11 +2734,6 @@ may also be used with field selectors when included in the `spec.versions[*].sel
27322734
{{< feature-state feature_gate_name="CustomResourceFieldSelectors" >}}
27332735
27342736
<!--
2735-
For Kubernetes {{< skew currentVersion >}} the ability to define field selectors for
2736-
custom resources is available by default (enabled by default since Kubernetes v1.31);
2737-
you can disable it for your cluster by turning off the `CustomResourceFieldSelectors`
2738-
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/).
2739-
27402737
The `spec.versions[*].selectableFields` field of a {{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}} may be used to
27412738
declare which other fields in a custom resource may be used in field selectors
27422739
with the feature of `CustomResourceFieldSelectors`
@@ -2746,11 +2743,6 @@ selectable fields.
27462743
27472744
Save the CustomResourceDefinition to `shirt-resource-definition.yaml`:
27482745
-->
2749-
在 Kubernetes {{< skew currentVersion >}} 中,
2750-
自定义资源的字段选择器功能默认启用(自 Kubernetes v1.31 起默认开启)。
2751-
如果你想禁用此功能,可以通过关闭 `CustomResourceFieldSelectors`
2752-
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/) 实现。
2753-
27542746
CustomResourceDefinition 的 `spec.versions[*].selectableFields`
27552747
字段可用于声明自定义资源中的哪些其他字段可在字段选择器中使用。
27562748
这一功能依赖于 `CustomResourceFieldSelectors`
@@ -2987,6 +2979,59 @@ Save the CustomResourceDefinition to `resourcedefinition.yaml`:
29872979

29882980
将此 CustomResourceDefinition 保存到 `resourcedefinition.yaml` 文件:
29892981

2982+
<!--
2983+
```yaml
2984+
apiVersion: apiextensions.k8s.io/v1
2985+
kind: CustomResourceDefinition
2986+
metadata:
2987+
name: crontabs.stable.example.com
2988+
spec:
2989+
group: stable.example.com
2990+
versions:
2991+
- name: v1
2992+
served: true
2993+
storage: true
2994+
schema:
2995+
openAPIV3Schema:
2996+
type: object
2997+
properties:
2998+
spec:
2999+
type: object
3000+
properties:
3001+
cronSpec:
3002+
type: string
3003+
image:
3004+
type: string
3005+
replicas:
3006+
type: integer
3007+
status:
3008+
type: object
3009+
properties:
3010+
replicas:
3011+
type: integer
3012+
labelSelector:
3013+
type: string
3014+
# subresources describes the subresources for custom resources.
3015+
subresources:
3016+
# status enables the status subresource.
3017+
status: {}
3018+
# scale enables the scale subresource.
3019+
scale:
3020+
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
3021+
specReplicasPath: .spec.replicas
3022+
# statusReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Replicas.
3023+
statusReplicasPath: .status.replicas
3024+
# labelSelectorPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Selector.
3025+
labelSelectorPath: .status.labelSelector
3026+
scope: Namespaced
3027+
names:
3028+
plural: crontabs
3029+
singular: crontab
3030+
kind: CronTab
3031+
shortNames:
3032+
- ct
3033+
```
3034+
-->
29903035
```yaml
29913036
apiVersion: apiextensions.k8s.io/v1
29923037
kind: CustomResourceDefinition
@@ -3239,9 +3284,7 @@ crontabs/my-new-cron-object 3s
32393284
32403285
* Serve [multiple versions](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/) of a
32413286
CustomResourceDefinition.
3242-
32433287
-->
32443288
* 阅读了解[定制资源](/zh-cn/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
32453289
* 参阅 [CustomResourceDefinition](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#customresourcedefinition-v1-apiextensions-k8s-io)
32463290
* 参阅支持 CustomResourceDefinition 的[多个版本](/zh-cn/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/)
3247-

0 commit comments

Comments
 (0)