@@ -4,7 +4,7 @@ content_type: concept
4
4
weight : 25
5
5
min-kubernetes-server-version : 1.16
6
6
---
7
- <!--
7
+ <!--
8
8
title: Server-Side Apply
9
9
reviewers:
10
10
- smarterclayton
@@ -35,7 +35,7 @@ declaratively by sending their fully specified intent.
35
35
声明式地创建和/或修改
36
36
[ 对象] ( /zh/docs/concepts/overview/working-with-objects/kubernetes-objects/ ) 。
37
37
38
- <!--
38
+ <!--
39
39
A fully specified intent is a partial object that only includes the fields and
40
40
values for which the user has an opinion. That intent either creates a new
41
41
object or is [combined](#merge-strategy), by the server, with the existing object.
@@ -48,7 +48,7 @@ The system supports multiple appliers collaborating on a single object.
48
48
49
49
系统支持多个应用者(appliers)在同一个对象上开展协作。
50
50
51
- <!--
51
+ <!--
52
52
Changes to an object's fields are tracked through a "[field management](#field-management)"
53
53
mechanism. When a field's value changes, ownership moves from its current
54
54
manager to the manager making the change. When trying to apply an object,
@@ -65,7 +65,7 @@ transferred.
65
65
冲突引发警告信号:此操作可能抹掉其他协作者的修改。
66
66
冲突可以被刻意忽略,这种情况下,值将会被改写,所有权也会发生转移。
67
67
68
- <!--
68
+ <!--
69
69
If you remove a field from a configuration and apply the configuration, server
70
70
side apply checks if there are any other field managers that also own the
71
71
field. If the field is not owned by any other field managers, it is either
@@ -77,7 +77,7 @@ same rule applies to associative list or map items.
77
77
如果没有,那就从活动对象中删除该字段;如果有,那就重置为默认值。
78
78
该规则同样适用于 list 或 map 项目。
79
79
80
- <!--
80
+ <!--
81
81
Server side apply is meant both as a replacement for the original `kubectl
82
82
apply` and as a simpler mechanism for controllers to enact their changes.
83
83
@@ -89,7 +89,7 @@ for all newly created objects.
89
89
90
90
如果你启用了服务器端应用,控制平面就会跟踪被所有新创建对象管理的字段。
91
91
92
- <!--
92
+ <!--
93
93
## Field Management
94
94
95
95
Compared to the `last-applied` annotation managed by `kubectl`, Server Side
@@ -106,7 +106,7 @@ field in an object also becomes available.
106
106
这就意味着,作为服务器端应用的一个副作用,
107
107
关于用哪一个字段管理器负责管理对象中的哪个字段的这类信息,都要对外界开放了。
108
108
109
- <!--
109
+ <!--
110
110
For a user to manage a field, in the Server Side Apply sense, means that the
111
111
user relies on and expects the value of the field not to change. The user who
112
112
last made an assertion about the value of a field will be recorded as the
@@ -118,13 +118,13 @@ request (if not forced, see [Conflicts](#conflicts)).
118
118
-->
119
119
用户管理字段这件事,在服务器端应用的场景中,意味着用户依赖并期望字段的值不要改变。
120
120
最后一次对字段值做出断言的用户将被记录到当前字段管理器。
121
- 这可以通过发送 ` POST ` 、 ` PUT ` 、
121
+ 这可以通过发送 ` POST ` 、 ` PUT ` 、
122
122
或非应用(non-apply)方式的 ` PATCH ` 等命令来修改字段值的方式实现,
123
123
或通过把字段放在配置文件中,然后发送到服务器端应用的服务端点的方式实现。
124
124
当使用服务器端应用,尝试着去改变一个被其他人管理的字段,
125
125
会导致请求被拒绝(在没有设置强制执行时,参见[ 冲突] ( #conflicts ) )。
126
126
127
- <!--
127
+ <!--
128
128
When two or more appliers set a field to the same value, they share ownership of
129
129
that field. Any subsequent attempt to change the value of the shared field, by any of
130
130
the appliers, results in a conflict. Shared field owners may give up ownership
@@ -139,7 +139,7 @@ A simple example of an object created by Server Side Apply could look like this:
139
139
后续任何改变共享字段值的尝试,不管由那个应用者发起,都会导致冲突。
140
140
共享字段的所有者可以放弃字段的所有权,这只需从配置文件中删除该字段即可。
141
141
142
- 字段管理的信息存储在 ` managedFields ` 字段中,该字段是对象的
142
+ 字段管理的信息存储在 ` managedFields ` 字段中,该字段是对象的
143
143
[ ` metadata ` ] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#objectmeta-v1-meta)
144
144
中的一部分。
145
145
@@ -169,7 +169,7 @@ data:
169
169
key : some value
170
170
` ` `
171
171
172
- <!--
172
+ <!--
173
173
The above object contains a single manager in ` metadata.managedFields`. The
174
174
manager consists of basic information about the managing entity itself, like
175
175
operation type, API version, and the fields managed by it.
@@ -184,7 +184,7 @@ the user.
184
184
该字段由 API 服务器管理,用户不应该改动它。
185
185
{{< /note >}}
186
186
187
- <!--
187
+ <!--
188
188
Nevertheless it is possible to change `metadata.managedFields` through an
189
189
` Update` operation. Doing so is highly discouraged, but might be a reasonable
190
190
option to try if, for example, the `managedFields` get into an inconsistent
@@ -202,7 +202,7 @@ The format of the `managedFields` is described in the
202
202
[API](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#fieldsv1-v1-meta)
203
203
文档中描述。
204
204
205
- <!--
205
+ <!--
206
206
# # Conflicts
207
207
208
208
A conflict is a special status error that occurs when an `Apply` operation tries
@@ -217,7 +217,7 @@ this occurs, the applier has 3 options to resolve the conflicts:
217
217
这可以防止一个应用者不小心覆盖掉其他用户设置的值。
218
218
冲突发生时,应用者有三种办法来解决它:
219
219
220
- <!--
220
+ <!--
221
221
* **Overwrite value, become sole manager:** If overwriting the value was
222
222
intentional (or if the applier is an automated process like a controller) the
223
223
applier should set the `force` query parameter to true and make the request
@@ -249,7 +249,7 @@ this occurs, the applier has 3 options to resolve the conflicts:
249
249
这样在不改变字段值的前提下,
250
250
就实现了字段管理被应用者和所有声明了管理权的其他的字段管理器共享。
251
251
252
- <!--
252
+ <!--
253
253
# # Managers
254
254
255
255
Managers identify distinct workflows that are modifying the object (especially
@@ -265,7 +265,7 @@ computed from the user-agent.
265
265
虽然 kubectl 默认发往 `kubectl` 服务端点,但它则请求到应用的服务端点(apply endpoint)。
266
266
对于其他的更新,它默认的是从用户代理计算得来。
267
267
268
- <!--
268
+ <!--
269
269
# # Apply and Update
270
270
271
271
The two operation types considered by this feature are `Apply` (`PATCH` with
@@ -292,7 +292,7 @@ All JSON documents are valid YAML.
292
292
所有的 JSON 文档 都是合法的 YAML。
293
293
{{< /note >}}
294
294
295
- <!--
295
+ <!--
296
296
For instance, only the apply operation fails on conflicts while update does
297
297
not. Also, apply operations are required to identify themselves by providing a
298
298
` fieldManager` query parameter, while the query parameter is optional for update
@@ -335,7 +335,7 @@ data:
335
335
key: new value
336
336
` ` `
337
337
338
- <!--
338
+ <!--
339
339
In this example, a second operation was run as an `Update` by the manager called
340
340
` kube-controller-manager` . The update changed a value in the data field which
341
341
caused the field's management to change to the `kube-controller-manager`.
@@ -350,7 +350,7 @@ would have failed due to conflicting ownership.
350
350
351
351
如果把 `update` 操作改为 `Apply`,那就会因为所有权冲突的原因,导致操作失败。
352
352
353
- <!--
353
+ <!--
354
354
# # Merge strategy
355
355
356
356
The merging strategy, implemented with Server Side Apply, provides a generally
@@ -364,7 +364,7 @@ multiple actors can update the same object without causing unexpected interferen
364
364
服务器端应用试图依据负责管理它们的主体来合并字段,而不是根据值来否决。
365
365
这么做是为了多个主体可以更新同一个对象,且不会引起意外的相互干扰。
366
366
367
- <!--
367
+ <!--
368
368
When a user sends a "fully-specified intent" object to the Server Side Apply
369
369
endpoint, the server merges it with the live object favoring the value in the
370
370
applied config if it is specified in both places. If the set of items present in
@@ -381,7 +381,7 @@ merging, see
381
381
关于合并时用来做决策的对象规格的更多信息,参见
382
382
[sigs.k8s.io/structured-merge-diff](https://sigs.k8s.io/structured-merge-diff).
383
383
384
- <!--
384
+ <!--
385
385
A number of markers were added in Kubernetes 1.16 and 1.17, to allow API
386
386
developers to describe the merge strategy supported by lists, maps, and
387
387
structs. These markers can be applied to objects of the respective type,
@@ -394,7 +394,7 @@ Kubernetes 1.16 和 1.17 中添加了一些标记,
394
394
[CRD](/docs/reference/generated/kubernetes-api/{{< param "version" >}}#jsonschemaprops-v1-apiextensions-k8s-io)
395
395
的 OpenAPI 的模式中定义:
396
396
397
- <!--
397
+ <!--
398
398
| Golang marker | OpenAPI extension | Accepted values | Description | Introduced in |
399
399
|---|---|---|---|---|
400
400
| `//+listType` | `x-kubernetes-list-type` | `atomic`/`set`/`map` | Applicable to lists. `set` applies to lists that include only scalar elements. These elements must be unique. `map` applies to lists of nested types only. The key values (see `listMapKey`) must be unique in the list. `atomic` can apply to any list. If configured as `atomic`, the entire list is replaced during merge. At any point in time, a single manager owns the list. If `set` or `map`, different managers can manage entries separately. | 1.16 |
@@ -507,7 +507,7 @@ manager can then modify or delete those fields without conflict.
507
507
` key1` 和 `key2`。因此,其他管理者可以在不引起冲突的情况下更改
508
508
或删除这些字段。
509
509
510
- <!--
510
+ <!--
511
511
# ## Custom Resources
512
512
513
513
By default, Server Side Apply treats custom resources as unstructured data. All
@@ -525,12 +525,12 @@ type.
525
525
所有的键值(keys)就像 struct 的字段一样被处理,
526
526
所有的 list 被认为是原子性的。
527
527
528
- 如果自定义资源定义(Custom Resource Definition,CRD)定义了一个
528
+ 如果自定义资源定义(Custom Resource Definition,CRD)定义了一个
529
529
[模式](/docs/reference/generated/kubernetes-api/{{< param "version" >}}#jsonschemaprops-v1-apiextensions-k8s-io),
530
530
它包含类似以前“合并策略”章节中定义过的注解,
531
531
这些注解将在合并此类型的对象时使用。
532
532
533
- <!--
533
+ <!--
534
534
# # Using Server-Side Apply in a controller
535
535
536
536
As a developer of a controller, you can use server-side apply as a way to
@@ -558,7 +558,7 @@ might not be able to resolve or act on these conflicts.
558
558
559
559
强烈推荐:设置控制器在冲突时强制执行,这是因为冲突发生时,它们没有其他解决方案或措施。
560
560
561
- <!--
561
+ <!--
562
562
# # Transferring Ownership
563
563
564
564
In addition to the concurrency controls provided by [conflict resolution](#conflicts),
@@ -586,7 +586,7 @@ Say a user has defined deployment with `replicas` set to the desired value:
586
586
587
587
{{< codenew file="application/ssa/nginx-deployment.yaml" >}}
588
588
589
- <!--
589
+ <!--
590
590
And the user has created the deployment using server side apply like so :
591
591
-->
592
592
并且,用户使用服务器端应用,像这样创建 Deployment:
@@ -595,7 +595,7 @@ And the user has created the deployment using server side apply like so:
595
595
kubectl apply -f https://k8s.io/examples/application/ssa/nginx-deployment.yaml --server-side
596
596
` ` `
597
597
598
- <!--
598
+ <!--
599
599
Then later, HPA is enabled for the deployment, e.g. :
600
600
-->
601
601
然后,为 Deployment 启用 HPA,例如:
@@ -604,7 +604,7 @@ Then later, HPA is enabled for the deployment, e.g.:
604
604
kubectl autoscale deployment nginx-deployment --cpu-percent=50 --min=1 --max=10
605
605
` ` `
606
606
607
- <!--
607
+ <!--
608
608
Now, the user would like to remove `replicas` from their configuration, so they
609
609
don't accidentally fight with the HPA controller. However, there is a race : it
610
610
might take some time before HPA feels the need to adjust `replicas`, and if
@@ -616,10 +616,10 @@ is not what the user wants to happen, even temporarily.
616
616
然而,这里存在一个竟态:
617
617
在 HPA 需要调整 `replicas` 之前会有一个时间窗口,
618
618
如果在 HPA 写入字段成为所有者之前,用户删除了`replicas`,
619
- 那 API 服务器就会把 `replicas` 的值设为1 , 也就是默认值。
619
+ 那 API 服务器就会把 `replicas` 的值设为 1 , 也就是默认值。
620
620
这不是用户希望发生的事情,即使是暂时的。
621
621
622
- <!--
622
+ <!--
623
623
There are two solutions :
624
624
625
625
- (basic) Leave `replicas` in the configuration; when HPA eventually writes to that
@@ -644,7 +644,7 @@ First, the user defines a new configuration containing only the `replicas` field
644
644
645
645
{{< codenew file="application/ssa/nginx-deployment-replicas-only.yaml" >}}
646
646
647
- <!--
647
+ <!--
648
648
The user applies that configuration using the field manager name `handover-to-hpa` :
649
649
-->
650
650
用户使用名为 `handover-to-hpa` 的字段管理器,应用此配置文件。
@@ -655,7 +655,7 @@ kubectl apply -f https://k8s.io/examples/application/ssa/nginx-deployment-replic
655
655
--validate=false
656
656
` ` `
657
657
658
- <!--
658
+ <!--
659
659
If the apply results in a conflict with the HPA controller, then do nothing. The
660
660
conflict indicates the controller has claimed the field earlier in the
661
661
process than it sometimes does.
@@ -669,7 +669,7 @@ At this point the user may remove the `replicas` field from their configuration.
669
669
670
670
{{< codenew file="application/ssa/nginx-deployment-no-replicas.yaml" >}}
671
671
672
- <!--
672
+ <!--
673
673
Note that whenever the HPA controller sets the `replicas` field to a new value,
674
674
the temporary field manager will no longer own any fields and will be
675
675
automatically deleted. No clean up is required.
@@ -678,7 +678,7 @@ automatically deleted. No clean up is required.
678
678
该临时字段管理器将不再拥有任何字段,会被自动删除。
679
679
这里不需要执行清理工作。
680
680
681
- <!--
681
+ <!--
682
682
# ## Transferring Ownership Between Users
683
683
684
684
Users can transfer ownership of a field between each other by setting the field
@@ -694,7 +694,7 @@ complete the transfer to the other user.
694
694
当用户共享了字段的所有权,任何一个用户可以从他的配置文件中删除该字段,
695
695
并应用该变更,从而放弃所有权,并实现了所有权向其他用户的转移。
696
696
697
- <!--
697
+ <!--
698
698
# # Comparison with Client Side Apply
699
699
700
700
A consequence of the conflict detection and resolution implemented by Server
@@ -727,7 +727,7 @@ case.
727
727
728
728
另一个区别是使用客户端应用的应用者不能改变他们正在使用的 API 版本,但服务器端应用支持这个场景。
729
729
730
- <!--
730
+ <!--
731
731
# # Upgrading from client-side apply to server-side apply
732
732
733
733
Client-side apply users who manage a resource with `kubectl apply` can start
@@ -741,7 +741,7 @@ using server-side apply with the following flag.
741
741
` ` ` shell
742
742
kubectl apply --server-side [--dry-run=server]
743
743
` ` `
744
- <!--
744
+ <!--
745
745
By default, field management of the object transfers from client-side apply to
746
746
kubectl server-side apply without encountering conflicts.
747
747
@@ -779,7 +779,7 @@ manager for kubectl server-side apply is `kubectl`.
779
779
kubectl apply --server-side --field-manager=my-manager [--dry-run=server]
780
780
` ` `
781
781
782
- <!--
782
+ <!--
783
783
# # Downgrading from server-side apply to client-side apply
784
784
785
785
If you manage a resource with `kubectl apply --server-side`,
@@ -810,7 +810,7 @@ manager for kubectl server-side apply is `kubectl`.
810
810
kubectl apply --server-side --field-manager=my-manager [--dry-run=server]
811
811
` ` `
812
812
813
- <!--
813
+ <!--
814
814
# # API Endpoint
815
815
816
816
With the Server Side Apply feature enabled, the `PATCH` endpoint accepts the
@@ -827,7 +827,7 @@ have an opinion about.
827
827
部分定义对象(partially specified objects)发送到此端点。
828
828
当一个配置文件被应用时,它应该包含所有体现你意图的字段。
829
829
830
- <!--
830
+ <!--
831
831
# # Clearing ManagedFields
832
832
833
833
It is possible to strip all managedFields from an object by overwriting them
@@ -838,7 +838,7 @@ with an empty entry. Two examples are:
838
838
# # 清除 ManagedFields {#clearing-managedfields}
839
839
840
840
可以从对象中剥离所有 managedField,
841
- 实现方法是通过使用 `MergePatch`、 `StrategicMergePatch`、
841
+ 实现方法是通过使用 `MergePatch`、 `StrategicMergePatch`、
842
842
` JSONPatch` 、 `Update`、以及所有的非应用方式的操作来覆盖它。
843
843
这可以通过用空条目覆盖 managedFields 字段的方式实现。
844
844
@@ -856,7 +856,7 @@ Accept: application/json
856
856
Data: [{"op": "replace", "path": "/metadata/managedFields", "value": [{}]}]
857
857
` ` `
858
858
859
- <!--
859
+ <!--
860
860
This will overwrite the managedFields with a list containing a single empty
861
861
entry that then results in the managedFields being stripped entirely from the
862
862
object. Note that setting the managedFields to an empty list will not
@@ -877,7 +877,7 @@ applier takes ownership of any fields updated in the same request.
877
877
将导致 managedFields 首先被重置,其他改变被押后处理。
878
878
其结果是,应用者取得了同一个请求中所有字段的所有权。
879
879
880
- <!--
880
+ <!--
881
881
Server Side Apply does not correctly track ownership on
882
882
sub-resources that don't receive the resource object type. If you are
883
883
using Server Side Apply with such a sub-resource, the changed fields
0 commit comments