@@ -18,7 +18,7 @@ weight: 25
18
18
19
19
{{< feature-state feature_gate_name="ServerSideApply" >}}
20
20
21
- <!--
21
+ <!--
22
22
Kubernetes supports multiple appliers collaborating to manage the fields
23
23
of a single [object](/docs/concepts/overview/working-with-objects/).
24
24
@@ -77,7 +77,7 @@ Kubernetes API 服务器跟踪所有新建对象的**受控字段(Managed Fiel
77
77
这样做是为了表明操作可能会撤消另一个合作者的更改。
78
78
可以强制写入具有托管字段的对象,在这种情况下,任何冲突字段的值都将被覆盖,并且所有权将被转移。
79
79
80
- <!--
80
+ <!--
81
81
Whenever a field's value does change, ownership moves from its current manager to the
82
82
manager making the change.
83
83
@@ -106,7 +106,7 @@ by including a value for that field in a Server-Side Apply operation.
106
106
最后一次对字段值做出断言的用户将被记录到当前字段管理器。
107
107
这可以通过发送 ` POST ` (** create** )、` PUT ` (** update** )、或非应用的 ` PATCH ` (** patch** )
108
108
显式更改字段管理器详细信息来实现。
109
- 还可以通过在服务器端应用操作中包含字段的值来声明和记录字段管理器 。
109
+ 你还可以通过在服务器端应用操作中包含字段的值来声明和记录字段管理器 。
110
110
111
111
<!--
112
112
A Server-Side Apply **patch** request requires the client to provide its identity
@@ -115,9 +115,8 @@ field that is controlled by a different manager results in a rejected
115
115
request unless the client forces an override.
116
116
For details of overrides, see [Conflicts](#conflicts).
117
117
-->
118
- 服务器端应用场景中的 ** patch** 请求要求客户端提供自身的标识作为
119
- [ 字段管理器(Field Manager)] ( #managers ) 。使用服务器端应用时,
120
- 如果尝试变更由别的管理器来控制的字段,会导致请求被拒绝,除非客户端强制要求进行覆盖。
118
+ 服务器端应用场景中的 ** patch** 请求要求客户端提供自身的标识作为[ 字段管理器(Field Manager)] ( #managers ) 。
119
+ 使用服务器端应用时,如果尝试变更由别的管理器来控制的字段,会导致请求被拒绝,除非客户端强制要求进行覆盖。
121
120
关于覆盖操作的细节,可参阅[ 冲突] ( #conflicts ) 节。
122
121
123
122
<!--
@@ -138,7 +137,7 @@ object's [`metadata`](/docs/reference/kubernetes-api/common-definitions/object-m
138
137
[ ` metadata ` ] ( /zh-cn/docs/reference/kubernetes-api/common-definitions/object-meta/ )
139
138
中的一部分。
140
139
141
- <!--
140
+ <!--
142
141
If you remove a field from a manifest and apply that manifest, Server-Side
143
142
Apply checks if there are any other field managers that also own the field.
144
143
If the field is not owned by any other field managers, it is either deleted
@@ -149,7 +148,7 @@ The same rule applies to associative list or map items.
149
148
如果该字段不属于任何其他字段管理器,则服务器会将其从活动对象中删除,或者重置为其默认值(如果有)。
150
149
同样的规则也适用于关联列表(list)或键值对(map)。
151
150
152
- <!--
151
+ <!--
153
152
Compared to the (legacy)
154
153
[`kubectl.kubernetes.io/last-applied-configuration`](/docs/reference/labels-annotations-taints/#kubectl-kubernetes-io-last-applied-configuration)
155
154
annotation managed by `kubectl`, Server-Side Apply uses a more declarative
@@ -164,7 +163,7 @@ becomes available.
164
163
它跟踪用户(或客户端)的字段管理,而不是用户上次应用的状态。
165
164
作为服务器端应用的副作用,哪个字段管理器管理的对象的哪个字段的相关信息也会变得可用。
166
165
167
- <!--
166
+ <!--
168
167
### Example {#ssa-example-configmap}
169
168
170
169
A simple example of an object created using Server-Side Apply could look like this:
@@ -173,6 +172,16 @@ A simple example of an object created using Server-Side Apply could look like th
173
172
174
173
服务器端应用创建对象的简单示例如下:
175
174
175
+ {{< note >}}
176
+ <!--
177
+ `kubectl get` omits managed fields by default.
178
+ Add `--show-managed-fields` to show `managedFields` when the output format is either `json` or `yaml`.
179
+ -->
180
+ ` kubectl get ` 默认省略 ` managedFields ` 。
181
+ 当输出格式为 ` json ` 或 ` yaml ` 时,你可以添加 ` --show-managed-fields ` 参数以显示 ` managedFields ` 。
182
+ {{< /note >}}
183
+
184
+ <!--
176
185
```yaml
177
186
---
178
187
apiVersion: v1
@@ -184,7 +193,32 @@ metadata:
184
193
test-label: test
185
194
managedFields:
186
195
- manager: kubectl
187
- operation : Apply # 注意大写: “Apply” (或者 “Update”)
196
+ operation: Apply # note capitalization: "Apply" (or "Update")
197
+ apiVersion: v1
198
+ time: "2010-10-10T0:00:00Z"
199
+ fieldsType: FieldsV1
200
+ fieldsV1:
201
+ f:metadata:
202
+ f:labels:
203
+ f:test-label: {}
204
+ f:data:
205
+ f:key: {}
206
+ data:
207
+ key: some value
208
+ ```
209
+ -->
210
+ ``` yaml
211
+ ---
212
+ apiVersion : v1
213
+ kind : ConfigMap
214
+ metadata :
215
+ name : test-cm
216
+ namespace : default
217
+ labels :
218
+ test-label : test
219
+ managedFields :
220
+ - manager : kubectl
221
+ operation : Apply # 注意大写:“Apply” (或者 “Update”)
188
222
apiVersion : v1
189
223
time : " 2010-10-10T0:00:00Z"
190
224
fieldsType : FieldsV1
@@ -198,7 +232,7 @@ data:
198
232
key : some value
199
233
` ` `
200
234
201
- <!--
235
+ <!--
202
236
That example ConfigMap object contains a single field management record in
203
237
` .metadata.managedFields`. The field management record consists of basic information
204
238
about the managing entity itself, plus details about the fields being managed and
@@ -208,9 +242,9 @@ otherwise, it is `Update`.
208
242
-->
209
243
示例的 ConfigMap 对象在 `.metadata.managedFields` 中包含字段管理记录。
210
244
字段管理记录包括关于管理实体本身的基本信息,以及关于被管理的字段和相关操作(`Apply` 或 `Update`)的详细信息。
211
- 如果最后更改该字段的请求是服务器端应用的**patch**操作,则 `operation` 的值为 `Apply`;否则为 `Update`。
245
+ 如果最后更改该字段的请求是服务器端应用的 **patch** 操作,则 `operation` 的值为 `Apply`;否则为 `Update`。
212
246
213
- <!--
247
+ <!--
214
248
There is another possible outcome. A client could submit an invalid request
215
249
body. If the fully specified intent does not produce a valid object, the
216
250
request fails.
@@ -229,7 +263,7 @@ for example, the `.metadata.managedFields` get into an inconsistent state
229
263
比如 `managedFields` 进入不一致的状态(显然不应该发生这种情况),
230
264
这么做也是一个合理的尝试。
231
265
232
- <!--
266
+ <!--
233
267
The format of `managedFields` is [described](/docs/reference/kubernetes-api/common-definitions/object-meta/#System)
234
268
in the Kubernetes API reference.
235
269
-->
@@ -322,20 +356,19 @@ sets the manager identity to `"kubectl"` by default.
322
356
323
357
当你使用 `kubectl` 工具执行服务器端应用操作时,`kubectl` 默认情况下会将管理器标识设置为 `“kubectl”`。
324
358
325
-
326
- <!--
359
+ <!--
327
360
# # Serialization
328
361
329
362
At the protocol level, Kubernetes represents Server-Side Apply message bodies
330
363
as [YAML](https://yaml.org/), with the media type `application/apply-patch+yaml`.
331
364
-->
332
365
# # 序列化 {#serialization}
333
366
334
- 在协议层面,Kubernetes 用 [YAML](https://yaml.org/) 来表示 Server-Side Apply 的消息体 ,
367
+ 在协议层面,Kubernetes 用 [YAML](https://yaml.org/) 来表示服务器端应用的消息体 ,
335
368
媒体类型为 `application/apply-patch+yaml`。
336
369
337
370
{{< note >}}
338
- <!--
371
+ <!--
339
372
Whether you are submitting JSON data or YAML data, use
340
373
` application/apply-patch+yaml` as the `Content-Type` header value.
341
374
@@ -368,15 +401,15 @@ Here's an example of a Server-Side Apply message body (fully specified intent):
368
401
}
369
402
` ` `
370
403
371
- <!--
404
+ <!--
372
405
(this would make a no-change update, provided that it was sent as the body
373
406
of a **patch** request to a valid `v1/configmaps` resource, and with the
374
407
appropriate request `Content-Type`).
375
408
-->
376
409
(这个请求将导致无更改的更新,前提是它作为 **patch** 请求的主体发送到有效的 `v1/configmaps` 资源,
377
410
并且请求中设置了合适的 `Content-Type`)。
378
411
379
- <!--
412
+ <!--
380
413
# # Operations in scope for field management {#apply-and-update}
381
414
382
415
The Kubernetes API operations where field management is considered are :
@@ -391,7 +424,7 @@ The Kubernetes API operations where field management is considered are:
391
424
1. 服务器端应用(HTTP `PATCH`,内容类型为 `application/apply-patch+yaml`)
392
425
2. 替换现有对象(对 Kubernetes 而言是 **update**;HTTP 层面表现为 `PUT`)
393
426
394
- <!--
427
+ <!--
395
428
Both operations update `.metadata.managedFields`, but behave a little differently.
396
429
397
430
Unless you specify a forced override, an apply operation that encounters field-level
@@ -548,7 +581,7 @@ keys are treated the same as struct fields, and all lists are considered atomic.
548
581
默认情况下,服务器端应用将自定义资源视为无结构的数据。
549
582
所有键被视为 struct 数据类型的字段,所有列表都被视为 atomic 形式。
550
583
551
- <!--
584
+ <!--
552
585
If the CustomResourceDefinition defines a
553
586
[schema](/docs/reference/generated/kubernetes-api/{{< param "version" >}}#jsonschemaprops-v1-apiextensions-k8s-io)
554
587
that contains annotations as defined in the previous [Merge Strategy](#merge-strategy)
@@ -612,10 +645,11 @@ kind: Foo
612
645
metadata:
613
646
name: foo-sample
614
647
managedFields:
615
- - manager: manager-one
648
+ - manager: " manager-one"
616
649
operation: Apply
617
650
apiVersion: example.com/v1
618
- fields:
651
+ fieldsType: FieldsV1
652
+ fieldsV1:
619
653
f:spec:
620
654
f:data: {}
621
655
spec:
@@ -725,8 +759,7 @@ This is not what the user wants to happen, even temporarily - it might well degr
725
759
a running workload.
726
760
-->
727
761
现在,用户希望从他们的配置中删除 `replicas`,从而避免与 HorizontalPodAutoscaler(HPA)及其控制器发生冲突。
728
- 然而,这里存在一个竞态:
729
- 在 HPA 需要调整 `.spec.replicas` 之前会有一个时间窗口,
762
+ 然而,这里存在一个竞态:在 HPA 需要调整 `.spec.replicas` 之前会有一个时间窗口,
730
763
如果在 HPA 写入字段并成为新的属主之前,用户删除了 `.spec.replicas`,
731
764
那 API 服务器就会把 `.spec.replicas` 的值设为 1(Deployment 的默认副本数)。
732
765
这不是用户希望发生的事情,即使是暂时的——它很可能会导致正在运行的工作负载降级。
@@ -754,6 +787,17 @@ First, the user defines a new manifest containing only the `replicas` field:
754
787
755
788
首先,用户新定义一个只包含 `replicas` 字段的新清单:
756
789
790
+ <!--
791
+ ` ` ` yaml
792
+ # Save this file as 'nginx-deployment-replicas-only.yaml'.
793
+ apiVersion: apps/v1
794
+ kind: Deployment
795
+ metadata:
796
+ name: nginx-deployment
797
+ spec:
798
+ replicas: 3
799
+ ` ` `
800
+ -->
757
801
` ` ` yaml
758
802
# 将此文件另存为 'nginx-deployment-replicas-only.yaml'
759
803
apiVersion: apps/v1
@@ -848,7 +892,7 @@ field in an object also becomes available.
848
892
服务器端应用使用一种更具声明性的方法来跟踪对象的字段管理,而不是记录用户最后一次应用的状态。
849
893
这意味着,使用服务器端应用的副作用,就是字段管理器所管理的对象的每个字段的相关信息也会变得可用。
850
894
851
- <!--
895
+ <!--
852
896
A consequence of the conflict detection and resolution implemented by Server-Side
853
897
Apply is that an applier always has up to date field values in their local
854
898
state. If they don't, they get a conflict the next time they apply. Any of the
@@ -895,6 +939,7 @@ using server-side apply with the following flag.
895
939
` ` ` shell
896
940
kubectl apply --server-side [--dry-run=server]
897
941
` ` `
942
+
898
943
<!--
899
944
By default, field management of the object transfers from client-side apply to
900
945
kubectl server-side apply, without encountering conflicts.
@@ -987,7 +1032,7 @@ request bodies that are also valid JSON.
987
1032
所有 JSON 消息都是有效的 YAML。一些客户端使用 YAML 请求体指定服务器端应用请求,
988
1033
而这些 YAML 同样是合法的 JSON。
989
1034
990
- <!--
1035
+ <!--
991
1036
# ## Access control and permissions {#rbac-and-permissions}
992
1037
993
1038
Since Server-Side Apply is a type of `PATCH`, a principal (such as a Role for Kubernetes
@@ -1062,7 +1107,7 @@ applier takes ownership of any fields updated in the same request.
1062
1107
其结果是,应用者取得了同一个请求中所有字段的所有权。
1063
1108
1064
1109
{{< note >}}
1065
- <!--
1110
+ <!--
1066
1111
Server-Side Apply does not correctly track ownership on
1067
1112
sub-resources that don't receive the resource object type. If you are
1068
1113
using Server-Side Apply with such a sub-resource, the changed fields
@@ -1074,7 +1119,7 @@ may not be tracked.
1074
1119
1075
1120
# # {{% heading "whatsnext" %}}
1076
1121
1077
- <!--
1122
+ <!--
1078
1123
You can read about `managedFields` within the Kubernetes API reference for the
1079
1124
[`metadata`](/docs/reference/kubernetes-api/common-definitions/object-meta/)
1080
1125
top level field.
0 commit comments