Skip to content

Commit cdca65a

Browse files
committed
[zh] Resync using-api/server-side-apply.md
1 parent 7801d4c commit cdca65a

File tree

1 file changed

+75
-30
lines changed

1 file changed

+75
-30
lines changed

content/zh-cn/docs/reference/using-api/server-side-apply.md

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ weight: 25
1818

1919
{{< feature-state feature_gate_name="ServerSideApply" >}}
2020

21-
<!--
21+
<!--
2222
Kubernetes supports multiple appliers collaborating to manage the fields
2323
of a single [object](/docs/concepts/overview/working-with-objects/).
2424
@@ -77,7 +77,7 @@ Kubernetes API 服务器跟踪所有新建对象的**受控字段(Managed Fiel
7777
这样做是为了表明操作可能会撤消另一个合作者的更改。
7878
可以强制写入具有托管字段的对象,在这种情况下,任何冲突字段的值都将被覆盖,并且所有权将被转移。
7979

80-
<!--
80+
<!--
8181
Whenever a field's value does change, ownership moves from its current manager to the
8282
manager making the change.
8383
@@ -106,7 +106,7 @@ by including a value for that field in a Server-Side Apply operation.
106106
最后一次对字段值做出断言的用户将被记录到当前字段管理器。
107107
这可以通过发送 `POST`**create**)、`PUT`**update**)、或非应用的 `PATCH`**patch**
108108
显式更改字段管理器详细信息来实现。
109-
还可以通过在服务器端应用操作中包含字段的值来声明和记录字段管理器
109+
你还可以通过在服务器端应用操作中包含字段的值来声明和记录字段管理器
110110

111111
<!--
112112
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
115115
request unless the client forces an override.
116116
For details of overrides, see [Conflicts](#conflicts).
117117
-->
118-
服务器端应用场景中的 **patch** 请求要求客户端提供自身的标识作为
119-
[字段管理器(Field Manager)](#managers)。使用服务器端应用时,
120-
如果尝试变更由别的管理器来控制的字段,会导致请求被拒绝,除非客户端强制要求进行覆盖。
118+
服务器端应用场景中的 **patch** 请求要求客户端提供自身的标识作为[字段管理器(Field Manager)](#managers)
119+
使用服务器端应用时,如果尝试变更由别的管理器来控制的字段,会导致请求被拒绝,除非客户端强制要求进行覆盖。
121120
关于覆盖操作的细节,可参阅[冲突](#conflicts)节。
122121

123122
<!--
@@ -138,7 +137,7 @@ object's [`metadata`](/docs/reference/kubernetes-api/common-definitions/object-m
138137
[`metadata`](/zh-cn/docs/reference/kubernetes-api/common-definitions/object-meta/)
139138
中的一部分。
140139

141-
<!--
140+
<!--
142141
If you remove a field from a manifest and apply that manifest, Server-Side
143142
Apply checks if there are any other field managers that also own the field.
144143
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.
149148
如果该字段不属于任何其他字段管理器,则服务器会将其从活动对象中删除,或者重置为其默认值(如果有)。
150149
同样的规则也适用于关联列表(list)或键值对(map)。
151150

152-
<!--
151+
<!--
153152
Compared to the (legacy)
154153
[`kubectl.kubernetes.io/last-applied-configuration`](/docs/reference/labels-annotations-taints/#kubectl-kubernetes-io-last-applied-configuration)
155154
annotation managed by `kubectl`, Server-Side Apply uses a more declarative
@@ -164,7 +163,7 @@ becomes available.
164163
它跟踪用户(或客户端)的字段管理,而不是用户上次应用的状态。
165164
作为服务器端应用的副作用,哪个字段管理器管理的对象的哪个字段的相关信息也会变得可用。
166165

167-
<!--
166+
<!--
168167
### Example {#ssa-example-configmap}
169168
170169
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
173172

174173
服务器端应用创建对象的简单示例如下:
175174

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+
<!--
176185
```yaml
177186
---
178187
apiVersion: v1
@@ -184,7 +193,32 @@ metadata:
184193
test-label: test
185194
managedFields:
186195
- 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”)
188222
apiVersion: v1
189223
time: "2010-10-10T0:00:00Z"
190224
fieldsType: FieldsV1
@@ -198,7 +232,7 @@ data:
198232
key: some value
199233
```
200234
201-
<!--
235+
<!--
202236
That example ConfigMap object contains a single field management record in
203237
`.metadata.managedFields`. The field management record consists of basic information
204238
about the managing entity itself, plus details about the fields being managed and
@@ -208,9 +242,9 @@ otherwise, it is `Update`.
208242
-->
209243
示例的 ConfigMap 对象在 `.metadata.managedFields` 中包含字段管理记录。
210244
字段管理记录包括关于管理实体本身的基本信息,以及关于被管理的字段和相关操作(`Apply` 或 `Update`)的详细信息。
211-
如果最后更改该字段的请求是服务器端应用的**patch**操作,则 `operation` 的值为 `Apply`;否则为 `Update`。
245+
如果最后更改该字段的请求是服务器端应用的 **patch** 操作,则 `operation` 的值为 `Apply`;否则为 `Update`。
212246

213-
<!--
247+
<!--
214248
There is another possible outcome. A client could submit an invalid request
215249
body. If the fully specified intent does not produce a valid object, the
216250
request fails.
@@ -229,7 +263,7 @@ for example, the `.metadata.managedFields` get into an inconsistent state
229263
比如 `managedFields` 进入不一致的状态(显然不应该发生这种情况),
230264
这么做也是一个合理的尝试。
231265

232-
<!--
266+
<!--
233267
The format of `managedFields` is [described](/docs/reference/kubernetes-api/common-definitions/object-meta/#System)
234268
in the Kubernetes API reference.
235269
-->
@@ -322,20 +356,19 @@ sets the manager identity to `"kubectl"` by default.
322356

323357
当你使用 `kubectl` 工具执行服务器端应用操作时,`kubectl` 默认情况下会将管理器标识设置为 `“kubectl”`。
324358

325-
326-
<!--
359+
<!--
327360
## Serialization
328361

329362
At the protocol level, Kubernetes represents Server-Side Apply message bodies
330363
as [YAML](https://yaml.org/), with the media type `application/apply-patch+yaml`.
331364
-->
332365
## 序列化 {#serialization}
333366

334-
在协议层面,Kubernetes 用 [YAML](https://yaml.org/) 来表示 Server-Side Apply 的消息体
367+
在协议层面,Kubernetes 用 [YAML](https://yaml.org/) 来表示服务器端应用的消息体
335368
媒体类型为 `application/apply-patch+yaml`。
336369

337370
{{< note >}}
338-
<!--
371+
<!--
339372
Whether you are submitting JSON data or YAML data, use
340373
`application/apply-patch+yaml` as the `Content-Type` header value.
341374

@@ -368,15 +401,15 @@ Here's an example of a Server-Side Apply message body (fully specified intent):
368401
}
369402
```
370403

371-
<!--
404+
<!--
372405
(this would make a no-change update, provided that it was sent as the body
373406
of a **patch** request to a valid `v1/configmaps` resource, and with the
374407
appropriate request `Content-Type`).
375408
-->
376409
(这个请求将导致无更改的更新,前提是它作为 **patch** 请求的主体发送到有效的 `v1/configmaps` 资源,
377410
并且请求中设置了合适的 `Content-Type`)。
378411

379-
<!--
412+
<!--
380413
## Operations in scope for field management {#apply-and-update}
381414

382415
The Kubernetes API operations where field management is considered are:
@@ -391,7 +424,7 @@ The Kubernetes API operations where field management is considered are:
391424
1. 服务器端应用(HTTP `PATCH`,内容类型为 `application/apply-patch+yaml`)
392425
2. 替换现有对象(对 Kubernetes 而言是 **update**;HTTP 层面表现为 `PUT`)
393426

394-
<!--
427+
<!--
395428
Both operations update `.metadata.managedFields`, but behave a little differently.
396429

397430
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.
548581
默认情况下,服务器端应用将自定义资源视为无结构的数据。
549582
所有键被视为 struct 数据类型的字段,所有列表都被视为 atomic 形式。
550583

551-
<!--
584+
<!--
552585
If the CustomResourceDefinition defines a
553586
[schema](/docs/reference/generated/kubernetes-api/{{< param "version" >}}#jsonschemaprops-v1-apiextensions-k8s-io)
554587
that contains annotations as defined in the previous [Merge Strategy](#merge-strategy)
@@ -612,10 +645,11 @@ kind: Foo
612645
metadata:
613646
name: foo-sample
614647
managedFields:
615-
- manager: manager-one
648+
- manager: "manager-one"
616649
operation: Apply
617650
apiVersion: example.com/v1
618-
fields:
651+
fieldsType: FieldsV1
652+
fieldsV1:
619653
f:spec:
620654
f:data: {}
621655
spec:
@@ -725,8 +759,7 @@ This is not what the user wants to happen, even temporarily - it might well degr
725759
a running workload.
726760
-->
727761
现在,用户希望从他们的配置中删除 `replicas`,从而避免与 HorizontalPodAutoscaler(HPA)及其控制器发生冲突。
728-
然而,这里存在一个竞态:
729-
在 HPA 需要调整 `.spec.replicas` 之前会有一个时间窗口,
762+
然而,这里存在一个竞态:在 HPA 需要调整 `.spec.replicas` 之前会有一个时间窗口,
730763
如果在 HPA 写入字段并成为新的属主之前,用户删除了 `.spec.replicas`,
731764
那 API 服务器就会把 `.spec.replicas` 的值设为 1(Deployment 的默认副本数)。
732765
这不是用户希望发生的事情,即使是暂时的——它很可能会导致正在运行的工作负载降级。
@@ -754,6 +787,17 @@ First, the user defines a new manifest containing only the `replicas` field:
754787

755788
首先,用户新定义一个只包含 `replicas` 字段的新清单:
756789

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+
-->
757801
```yaml
758802
# 将此文件另存为 'nginx-deployment-replicas-only.yaml'
759803
apiVersion: apps/v1
@@ -848,7 +892,7 @@ field in an object also becomes available.
848892
服务器端应用使用一种更具声明性的方法来跟踪对象的字段管理,而不是记录用户最后一次应用的状态。
849893
这意味着,使用服务器端应用的副作用,就是字段管理器所管理的对象的每个字段的相关信息也会变得可用。
850894

851-
<!--
895+
<!--
852896
A consequence of the conflict detection and resolution implemented by Server-Side
853897
Apply is that an applier always has up to date field values in their local
854898
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.
895939
```shell
896940
kubectl apply --server-side [--dry-run=server]
897941
```
942+
898943
<!--
899944
By default, field management of the object transfers from client-side apply to
900945
kubectl server-side apply, without encountering conflicts.
@@ -987,7 +1032,7 @@ request bodies that are also valid JSON.
9871032
所有 JSON 消息都是有效的 YAML。一些客户端使用 YAML 请求体指定服务器端应用请求,
9881033
而这些 YAML 同样是合法的 JSON。
9891034

990-
<!--
1035+
<!--
9911036
### Access control and permissions {#rbac-and-permissions}
9921037

9931038
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.
10621107
其结果是,应用者取得了同一个请求中所有字段的所有权。
10631108

10641109
{{< note >}}
1065-
<!--
1110+
<!--
10661111
Server-Side Apply does not correctly track ownership on
10671112
sub-resources that don't receive the resource object type. If you are
10681113
using Server-Side Apply with such a sub-resource, the changed fields
@@ -1074,7 +1119,7 @@ may not be tracked.
10741119

10751120
## {{% heading "whatsnext" %}}
10761121

1077-
<!--
1122+
<!--
10781123
You can read about `managedFields` within the Kubernetes API reference for the
10791124
[`metadata`](/docs/reference/kubernetes-api/common-definitions/object-meta/)
10801125
top level field.

0 commit comments

Comments
 (0)