@@ -118,7 +118,7 @@ metadata:
118
118
# 名字必需与下面的 spec 字段匹配,并且格式为 '<名称的复数形式>.<组名>'
119
119
name : crontabs.stable.example.com
120
120
spec :
121
- # 组名称,用于 REST API: /apis/<组>/<版本>
121
+ # 组名称,用于 REST API: /apis/<组>/<版本>
122
122
group : stable.example.com
123
123
# 列举此 CustomResourceDefinition 所支持的版本
124
124
versions :
@@ -182,12 +182,11 @@ You can watch the `Established` condition of your CustomResourceDefinition
182
182
to be true or watch the discovery information of the API server for your
183
183
resource to show up.
184
184
-->
185
- 此端点 URL 自此可以用来创建和管理定制对象。对象的 ` kind ` 将是来自你上面创建时
186
- 所用的 spec 中指定的 ` CronTab ` 。
185
+ 此端点 URL 自此可以用来创建和管理定制对象。对象的 ` kind `
186
+ 将是来自你上面创建时所用的规约中指定的 ` CronTab ` 。
187
187
188
188
创建端点的操作可能需要几秒钟。你可以监测你的 CustomResourceDefinition 的
189
- ` Established ` 状况变为 true,或者监测 API 服务器的发现信息等待你的资源出现在
190
- 那里。
189
+ ` Established ` 状况变为 true,或者监测 API 服务器的发现信息等待你的资源出现在那里。
191
190
192
191
<!--
193
192
## Create custom objects
@@ -254,8 +253,8 @@ the singular or plural forms defined in the CRD, as well as any short names.
254
253
255
254
You can also view the raw YAML data:
256
255
-->
257
- 使用 kubectl 时,资源名称是大小写不敏感的,而且你既可以使用 CRD 中所定义的单数
258
- 形式或复数形式 ,也可以使用其短名称:
256
+ 使用 kubectl 时,资源名称是大小写不敏感的,而且你既可以使用 CRD
257
+ 中所定义的单数形式或复数形式 ,也可以使用其短名称:
259
258
260
259
``` shell
261
260
kubectl get ct -o yaml
@@ -335,12 +334,12 @@ CustomResourceDefinition, the structural schema was optional.
335
334
336
335
CustomResource 对象在定制字段中保存结构化的数据,这些字段和内置的字段
337
336
` apiVersion ` 、` kind ` 和 ` metadata ` 等一起存储,不过内置的字段都会被 API
338
- 服务器隐式完成合法性检查。有了 [ OpenAPI v3.0 检查] ( #validation )
339
- 能力之后, 你可以设置一个模式(Schema),在创建和更新定制对象时,这一模式会被用来
337
+ 服务器隐式完成合法性检查。有了 [ OpenAPI v3.0 检查] ( #validation ) 能力之后,
338
+ 你可以设置一个模式(Schema),在创建和更新定制对象时,这一模式会被用来
340
339
对对象内容进行合法性检查。参阅下文了解这类模式的细节和局限性。
341
340
342
- 在 ` apiextensions.k8s.io/v1 ` 版本中,CustomResourceDefinition 的这一结构化模式
343
- 定义是必需的 。
341
+ 在 ` apiextensions.k8s.io/v1 ` 版本中,CustomResourceDefinition
342
+ 的这一结构化模式定义是必需的 。
344
343
在 CustomResourceDefinition 的 beta 版本中,结构化模式定义是可选的。
345
344
346
345
<!--
@@ -375,7 +374,7 @@ A structural schema is an [OpenAPI v3.0 validation schema](#validation) which:
375
374
<!--
376
375
Non-structural example 1:
377
376
-->
378
- 非结构化的例 1:
377
+ 非结构化的例 1:
379
378
380
379
``` none
381
380
allOf:
@@ -616,8 +615,8 @@ to clients, `kubectl` also checks for unknown fields and rejects those objects w
616
615
would be sent to the API server.
617
616
-->
618
617
本例中通过 `--validate=false` 命令行选项 关闭了客户端的合法性检查以展示 API 服务器的行为,
619
- 因为 [OpenAPI 合法性检查模式也会发布到](#publish-validation-schema-in-openapi)
620
- 客户端, `kubectl` 也会检查未知的字段并在对象被发送到 API
618
+ 因为 [OpenAPI 合法性检查模式也会发布到](#publish-validation-schema-in-openapi)客户端,
619
+ ` kubectl` 也会检查未知的字段并在对象被发送到 API
621
620
服务器之前就拒绝它们。
622
621
623
622
<!--
@@ -632,8 +631,8 @@ For example:
632
631
# ### 控制剪裁 {#controlling-pruning}
633
632
634
633
默认情况下,定制资源的所有版本中的所有未规定的字段都会被剪裁掉。
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` 属性,
637
636
可以选择不对其执行剪裁操作。
638
637
639
638
例如:
@@ -755,6 +754,9 @@ anyOf:
755
754
...
756
755
` ` `
757
756
757
+ <!--
758
+ and
759
+ -->
758
760
和
759
761
760
762
` ` ` none
@@ -973,7 +975,7 @@ The `x-kubernetes-validations` extension can be used to validate custom resource
973
975
当[验证规则特性](#validation-rules)被启用并且 CustomResourceDefinition
974
976
模式是一个[结构化的模式定义](#specifying-a-structural-schema)时,
975
977
` x-kubernetes-validations`
976
- 扩展可以使用[通用表达式语言 ( CEL) ](https://github.com/google/cel-spec)表达式来验证定制资源。
978
+ 扩展可以使用[通用表达式语言( CEL) ](https://github.com/google/cel-spec)表达式来验证定制资源。
977
979
978
980
<!--
979
981
Refer to the [structural schemas](#specifying-a-structural-schema) section for other
@@ -1296,7 +1298,7 @@ rules are supported.
1296
1298
<!--
1297
1299
For example :
1298
1300
-->
1299
- 例如 :
1301
+ 例如:
1300
1302
1301
1303
` ` ` none
1302
1304
...
@@ -1327,7 +1329,7 @@ For example:
1327
1329
<!--
1328
1330
will reject a request to create this custom resource :
1329
1331
-->
1330
- 将拒绝创建这个定制资源的请求 :
1332
+ 将拒绝创建这个定制资源的请求:
1331
1333
1332
1334
` ` ` yaml
1333
1335
apiVersion: "stable.example.com/v1"
@@ -2732,11 +2734,6 @@ may also be used with field selectors when included in the `spec.versions[*].sel
2732
2734
{{< feature-state feature_gate_name="CustomResourceFieldSelectors" >}}
2733
2735
2734
2736
<!--
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
-
2740
2737
The `spec.versions[*].selectableFields` field of a {{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}} may be used to
2741
2738
declare which other fields in a custom resource may be used in field selectors
2742
2739
with the feature of `CustomResourceFieldSelectors`
@@ -2746,11 +2743,6 @@ selectable fields.
2746
2743
2747
2744
Save the CustomResourceDefinition to `shirt-resource-definition.yaml`:
2748
2745
-->
2749
- 在 Kubernetes {{< skew currentVersion >}} 中,
2750
- 自定义资源的字段选择器功能默认启用(自 Kubernetes v1.31 起默认开启)。
2751
- 如果你想禁用此功能,可以通过关闭 `CustomResourceFieldSelectors`
2752
- [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/) 实现。
2753
-
2754
2746
CustomResourceDefinition 的 `spec.versions[*].selectableFields`
2755
2747
字段可用于声明自定义资源中的哪些其他字段可在字段选择器中使用。
2756
2748
这一功能依赖于 `CustomResourceFieldSelectors`
@@ -2987,6 +2979,59 @@ Save the CustomResourceDefinition to `resourcedefinition.yaml`:
2987
2979
2988
2980
将此 CustomResourceDefinition 保存到 ` resourcedefinition.yaml ` 文件:
2989
2981
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
+ -->
2990
3035
``` yaml
2991
3036
apiVersion : apiextensions.k8s.io/v1
2992
3037
kind : CustomResourceDefinition
@@ -3239,9 +3284,7 @@ crontabs/my-new-cron-object 3s
3239
3284
3240
3285
* Serve [multiple versions](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/) of a
3241
3286
CustomResourceDefinition.
3242
-
3243
3287
-->
3244
3288
* 阅读了解[ 定制资源] ( /zh-cn/docs/concepts/extend-kubernetes/api-extension/custom-resources/ )
3245
3289
* 参阅 [ CustomResourceDefinition] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#customresourcedefinition-v1-apiextensions-k8s-io)
3246
3290
* 参阅支持 CustomResourceDefinition 的[ 多个版本] ( /zh-cn/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/ )
3247
-
0 commit comments