diff --git a/content/zh-cn/docs/reference/using-api/server-side-apply.md b/content/zh-cn/docs/reference/using-api/server-side-apply.md index 5e15982b9a..288b49ce43 100644 --- a/content/zh-cn/docs/reference/using-api/server-side-apply.md +++ b/content/zh-cn/docs/reference/using-api/server-side-apply.md @@ -23,8 +23,8 @@ min-kubernetes-server-version: 1.16 @@ -32,8 +32,7 @@ declaratively by sending their fully specified intent. 服务器端应用协助用户、控制器通过声明式配置的方式管理他们的资源。 客户端可以发送完整描述的目标(A fully specified intent), -声明式地创建和/或修改 -[对象](/zh-cn/docs/concepts/overview/working-with-objects/kubernetes-objects/)。 +声明式地创建和修改[对象](/zh-cn/docs/concepts/overview/working-with-objects/kubernetes-objects/)。 当你从配置文件中删除一个字段,然后应用这个配置文件, -这将触发服务端应用检查此字段是否还被其他字段管理器拥有。 +将触发服务器端应用检查此字段是否还被其他字段管理器拥有。 如果没有,那就从活动对象中删除该字段;如果有,那就重置为默认值。 该规则同样适用于 list 或 map 项目。 服务器端应用既是原有 `kubectl apply` 的替代品, @@ -92,10 +91,10 @@ for all newly created objects. ## 字段管理 {#field-management} @@ -107,12 +106,12 @@ field in an object also becomes available. 关于用哪一个字段管理器负责管理对象中的哪个字段的这类信息,都要对外界开放了。 @@ -133,7 +132,7 @@ of a field by removing it from their configuration. Field management is stored in a`managedFields` field that is part of an object's [`metadata`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#objectmeta-v1-meta). -A simple example of an object created by Server Side Apply could look like this: +A simple example of an object created by Server-Side Apply could look like this: --> 如果两个或以上的应用者均把同一个字段设置为相同值,他们将共享此字段的所有权。 后续任何改变共享字段值的尝试,不管由那个应用者发起,都会导致冲突。 @@ -173,14 +172,15 @@ data: The above object contains a single manager in `metadata.managedFields`. The manager consists of basic information about the managing entity itself, like operation type, API version, and the fields managed by it. - -This field is managed by the API server and should not be changed by -the user. --> 上述对象在 `metadata.managedFields` 中包含了唯一的管理器。 管理器由管理实体自身的基本信息组成,比如操作类型、API 版本、以及它管理的字段。 {{< note >}} + 该字段由 API 服务器管理,用户不应该改动它。 {{< /note >}} @@ -274,11 +274,6 @@ The two operation types considered by this feature are `Apply` (`PATCH` with content type `application/apply-patch+yaml`) and `Update` (all other operations which modify the object). Both operations update the `managedFields`, but behave a little differently. - -Whether you are submitting JSON data or YAML data, use -`application/apply-patch+yaml` as the `Content-Type` header value. - -All JSON documents are valid YAML. --> ## 应用和更新 {#apply-and-update} @@ -288,6 +283,12 @@ All JSON documents are valid YAML. 这两类操作都会更新字段 `managedFields`,但行为表现有一点不同。 {{< note >}} + 不管你提交的是 JSON 数据还是 YAML 数据, 都要使用 `application/apply-patch+yaml` 作为 `Content-Type` 的值。 @@ -355,8 +356,8 @@ would have failed due to conflicting ownership. @@ -367,7 +368,7 @@ multiple actors can update the same object without causing unexpected interferen 这么做是为了多个主体可以更新同一个对象,且不会引起意外的相互干扰。 -### 自定义资源 {#custom-resources} +## 自定义资源 {#custom-resources} 默认情况下,服务器端应用把自定义资源看做非结构化数据。 所有的键值(keys)就像 struct 的字段一样被处理, @@ -540,7 +541,7 @@ simplify the update logic of your controller. The main differences with a read-modify-write and/or patch are the following: * the applied object must contain all the fields that the controller cares about. -* there are no way to remove fields that haven't been applied by the controller +* there is no way to remove fields that haven't been applied by the controller before (controller can still send a PATCH/UPDATE for these use-cases). * the object doesn't have to be read beforehand, `resourceVersion` doesn't have to be specified. @@ -564,7 +565,7 @@ might not be able to resolve or act on these conflicts. ## Transferring Ownership In addition to the concurrency controls provided by [conflict resolution](#conflicts), -Server Side Apply provides ways to perform coordinated +Server-Side Apply provides ways to perform coordinated field ownership transfers from users to controllers. This is best explained by example. Let's look at how to safely transfer @@ -589,7 +590,7 @@ Say a user has defined deployment with `replicas` set to the desired value: {{< codenew file="application/ssa/nginx-deployment.yaml" >}} 并且,用户使用服务器端应用,像这样创建 Deployment: @@ -699,8 +700,8 @@ complete the transfer to the other user. ## 与客户端应用的对比 {#comparison-with-client-side-apply} @@ -746,7 +747,11 @@ kubectl apply --server-side [--dry-run=server] +默认情况下,对象的字段管理从客户端应用方式迁移到 kubectl 触发的服务器端应用时,不会发生冲突。 +{{< caution >}} + -默认情况下,对象的字段管理从客户端应用方式迁移到 kubectl 触发的服务器端应用时,不会发生冲突。 - -{{< caution >}} 保持注解 `last-applied-configuration` 是最新的。 从注解能推断出字段是由客户端应用管理的。 任何没有被客户端应用管理的字段将引发冲突。 @@ -773,6 +770,12 @@ manager for kubectl server-side apply is `kubectl`. 在执行 `kubectl apply --server-side` 时就会产生冲突。 {{< /caution >}} + 此操作以 `kubectl` 作为字段管理器来应用到服务器端应用。 作为例外,可以指定一个不同的、非默认字段管理器停止的这种行为,如下面的例子所示。 对于 kubectl 触发的服务器端应用,默认的字段管理器是 `kubectl`。 @@ -815,8 +818,8 @@ kubectl apply --server-side --field-manager=my-manager [--dry-run=server] +### RBAC 和权限 {#rbac-and-permissions} + +因为服务器端应用是一种 `PATCH` 操作,所以一个角色编辑资源需要 `PATCH` 权限, +但要用服务器端应用创建资源还需要 `CREATE` 动作权限。 + @@ -879,14 +894,3 @@ applier takes ownership of any fields updated in the same request. 将导致 managedFields 首先被重置,其他改变被押后处理。 其结果是,应用者取得了同一个请求中所有字段的所有权。 - -{{< caution >}} -对于不接受资源对象类型的子资源(sub-resources), -服务器端应用不能正确地跟踪其所有权。 -如果你对这样的子资源使用服务器端应用,变更的字段将不会被跟踪。 -{{< /caution >}}