Skip to content

Commit 0bd8dc0

Browse files
committed
[zh-cn] resync update-api-object-kubectl-patch.md
1 parent 4ee9724 commit 0bd8dc0

File tree

1 file changed

+55
-60
lines changed

1 file changed

+55
-60
lines changed

content/zh-cn/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch.md

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ in this task demonstrate a strategic merge patch and a JSON merge patch.
2121
这个任务展示如何使用 `kubectl patch` 就地更新 API 对象。
2222
这个任务中的练习演示了一个策略性合并 patch 和一个 JSON 合并 patch。
2323

24-
2524
## {{% heading "prerequisites" %}}
2625

2726
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
@@ -62,7 +61,7 @@ kubectl get pods
6261
The output shows that the Deployment has two Pods. The `1/1` indicates that
6362
each Pod has one container:
6463
-->
65-
输出显示 Deployment 有两个 Pod。`1/1` 表示每个 Pod 有一个容器:
64+
输出显示 Deployment 有两个 Pod。`1/1` 表示每个 Pod 有一个容器
6665

6766
```
6867
NAME READY STATUS RESTARTS AGE
@@ -85,7 +84,7 @@ you want each Pod to have two containers: one that runs nginx and one that runs
8584
<!--
8685
Create a file named `patch-file.yaml` that has this content:
8786
-->
88-
创建一个名为 `patch-file.yaml` 的文件。内容如下:
87+
创建一个名为 `patch-file.yaml` 的文件。内容如下
8988

9089
```yaml
9190
spec:
@@ -116,7 +115,7 @@ kubectl get deployment patch-demo --output yaml
116115
<!--
117116
The output shows that the PodSpec in the Deployment has two Containers:
118117
-->
119-
输出显示 Deployment 中的 PodSpec 有两个容器:
118+
输出显示 Deployment 中的 PodSpec 有两个容器
120119

121120
```yaml
122121
containers:
@@ -133,7 +132,7 @@ containers:
133132
<!--
134133
View the Pods associated with your patched Deployment:
135134
-->
136-
查看与 patch Deployment 相关的 Pod:
135+
查看与 patch Deployment 相关的 Pod
137136

138137
```shell
139138
kubectl get pods
@@ -145,8 +144,8 @@ were running previously. The Deployment terminated the old Pods and created two
145144
new Pods that comply with the updated Deployment spec. The `2/2` indicates that
146145
each Pod has two Containers:
147146
-->
148-
输出显示正在运行的 Pod 与以前运行的 Pod 有不同的名称。Deployment 终止了旧的 Pod,并创建了两个
149-
符合更新的部署规范的新 Pod。`2/2` 表示每个 Pod 有两个容器:
147+
输出显示正在运行的 Pod 与以前运行的 Pod 有不同的名称。Deployment 终止了旧的 Pod,
148+
并创建了两个符合更新后的 Deployment 规约的新 Pod。`2/2` 表示每个 Pod 有两个容器:
150149

151150
```
152151
NAME READY STATUS RESTARTS AGE
@@ -157,7 +156,7 @@ patch-demo-1081991389-jmg7b 2/2 Running 0 1m
157156
<!--
158157
Take a closer look at one of the patch-demo Pods:
159158
-->
160-
仔细查看其中一个 patch-demo Pod:
159+
仔细查看其中一个 patch-demo Pod
161160

162161
```shell
163162
kubectl get pod <your-pod-name> --output yaml
@@ -166,7 +165,7 @@ kubectl get pod <your-pod-name> --output yaml
166165
<!--
167166
The output shows that the Pod has two Containers: one running nginx and one running redis:
168167
-->
169-
输出显示 Pod 有两个容器:一个运行 nginx,一个运行 redis:
168+
输出显示 Pod 有两个容器一个运行 nginx,一个运行 redis
170169

171170
```
172171
containers:
@@ -206,25 +205,29 @@ patch 策略由 Kubernetes 源代码中字段标记中的 `patchStrategy` 键的
206205
type PodSpec struct {
207206
...
208207
Containers []Container `json:"containers" patchStrategy:"merge" patchMergeKey:"name" ...`
208+
...
209+
}
209210
```
210211

211212
<!--
212213
You can also see the patch strategy in the
213214
[OpenApi spec](https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json):
214215
-->
215-
你还可以在 [OpenApi spec](https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json)
216-
规范中看到 patch 策略:
216+
你还可以在
217+
[OpenApi 规范](https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json)中看到
218+
patch 策略:
217219

218-
```json
220+
```yaml
219221
"io.k8s.api.core.v1.PodSpec": {
220-
...
221-
"containers": {
222-
"description": "List of containers belonging to the pod. ...
223-
},
224-
"x-kubernetes-patch-merge-key": "name",
225-
"x-kubernetes-patch-strategy": "merge"
226-
},
222+
...,
223+
"containers": {
224+
"description": "List of containers belonging to the pod. ...."
225+
},
226+
"x-kubernetes-patch-merge-key": "name",
227+
"x-kubernetes-patch-strategy": "merge"
228+
}
227229
```
230+
<!-- for editors: intionally use yaml instead of json here, to prevent syntax highlight error. -->
228231

229232
<!--
230233
And you can see the patch strategy in the
@@ -253,7 +256,7 @@ Patch your Deployment:
253256
-->
254257
对 Deployment 执行 patch 操作:
255258
256-
```
259+
```shell
257260
kubectl patch deployment patch-demo --patch-file patch-file-tolerations.yaml
258261
```
259262

@@ -271,23 +274,11 @@ The output shows that the PodSpec in the Deployment has only one Toleration:
271274
-->
272275
输出结果显示 Deployment 中的 PodSpec 只有一个容忍度设置:
273276

274-
```shell
275-
276-
containers:
277-
- image: redis
278-
imagePullPolicy: Always
279-
name: patch-demo-ctr-2
280-
...
281-
- image: nginx
282-
imagePullPolicy: Always
283-
name: patch-demo-ctr
284-
...
285-
```
286277
```yaml
287278
tolerations:
288-
- effect: NoSchedule
289-
key: disktype
290-
value: ssd
279+
- effect: NoSchedule
280+
key: disktype
281+
value: ssd
291282
```
292283
293284
<!--
@@ -302,6 +293,8 @@ strategic merge patch uses the default patch strategy, which is `replace`.
302293
type PodSpec struct {
303294
...
304295
Tolerations []Toleration `json:"tolerations,omitempty" protobuf:"bytes,22,opt,name=tolerations"`
296+
...
297+
}
305298
```
306299

307300
<!--
@@ -321,7 +314,7 @@ replaces the existing list.
321314
<!--
322315
The `kubectl patch` command has a `type` parameter that you can set to one of these values:
323316
-->
324-
`kubectl patch` 命令有一个 `type` 参数,你可以将其设置为以下值之一:
317+
`kubectl patch` 命令有一个 `type` 参数,你可以将其设置为以下值之一
325318

326319
<table>
327320
<!--
@@ -353,7 +346,7 @@ did a strategic merge patch.
353346
Next, do a JSON merge patch on your same Deployment. Create a file named `patch-file-2.yaml`
354347
that has this content:
355348
-->
356-
下一步,在相同的 Deployment 上执行 JSON 合并 patch。创建一个名为 `patch-file-2` 的文件。内容如下:
349+
下一步,在相同的 Deployment 上执行 JSON 合并 patch。创建一个名为 `patch-file-2` 的文件。内容如下
357350

358351
```yaml
359352
spec:
@@ -400,7 +393,7 @@ spec:
400393
<!--
401394
List the running Pods:
402395
-->
403-
列表中运行的 Pod:
396+
列出正运行的 Pod:
404397

405398
```shell
406399
kubectl get pods
@@ -475,8 +468,8 @@ The way to remove the value for `spec.strategy.rollingUpdate` when updating the
475468
476469
Create another file named `patch-file-retainkeys.yaml` that has this content:
477470
-->
478-
更新 `type` 取值的同时移除 `spec.strategy.rollingUpdate` 现有值的方法是
479-
为策略性合并操作设置 `retainKeys` 策略:
471+
更新 `type` 取值的同时移除 `spec.strategy.rollingUpdate`
472+
现有值的方法是为策略性合并操作设置 `retainKeys` 策略:
480473
481474
创建另一个名为 `patch-file-retainkeys.yaml` 的文件,内容如下:
482475
@@ -536,8 +529,8 @@ The patch you did in the preceding exercise is called a *strategic merge patch w
536529
-->
537530
### 关于使用 retainKeys 策略的策略合并 patch 操作的说明 {#notes-on-the-strategic-merge-patch-using-the-retainkeys-strategy}
538531

539-
在前文练习中所执行的称作 *带 `retainKeys` 策略的策略合并 patch(Strategic Merge
540-
Patch with retainKeys Strategy)*。
532+
在前文练习中所执行的称作 **带 `retainKeys` 策略的策略合并 patch(Strategic Merge
533+
Patch with retainKeys Strategy)**
541534
这种方法引入了一种新的 `$retainKey` 指令,具有如下策略:
542535

543536
- 其中包含一个字符串列表;
@@ -559,30 +552,37 @@ type DeploymentSpec struct {
559552
...
560553
// +patchStrategy=retainKeys
561554
Strategy DeploymentStrategy `json:"strategy,omitempty" patchStrategy:"retainKeys" ...`
555+
...
556+
}
562557
```
563558

564559
<!--
565560
You can also see the `retainKeys` strategy in the [OpenApi spec](https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json):
566561
-->
567-
你也可以查看 [OpenAPI 规范](https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json)中的 `retainKeys` 策略:
562+
你也可以查看
563+
[OpenAPI 规范](https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json)中的
564+
`retainKeys` 策略:
568565

569-
```json
566+
```yaml
570567
"io.k8s.api.apps.v1.DeploymentSpec": {
571-
...
572-
"strategy": {
573-
"$ref": "#/definitions/io.k8s.api.apps.v1.DeploymentStrategy",
574-
"description": "The deployment strategy to use to replace existing pods with new ones.",
575-
"x-kubernetes-patch-strategy": "retainKeys"
576-
},
568+
...,
569+
"strategy": {
570+
"$ref": "#/definitions/io.k8s.api.apps.v1.DeploymentStrategy",
571+
"description": "The deployment strategy to use to replace existing pods with new ones.",
572+
"x-kubernetes-patch-strategy": "retainKeys"
573+
},
574+
....
575+
}
577576
```
577+
<!-- for editors: intionally use yaml instead of json here, to prevent syntax highlight error. -->
578578

579579
<!--
580580
And you can see the `retainKeys` strategy in the
581581
[Kubernetes API documentation](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#deploymentspec-v1-apps).
582582
-->
583583
而且你也可以在
584-
[Kubernetes API 文档](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#deploymentspec-v1-apps).
585-
中看到 `retainKey` 策略。
584+
[Kubernetes API 文档](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#deploymentspec-v1-apps)中看到
585+
`retainKey` 策略。
586586

587587
<!--
588588
## Alternate forms of the kubectl patch command
@@ -592,8 +592,7 @@ directly on the command line.
592592
-->
593593
## kubectl patch 命令的其他形式 {#alternate-forms-of-the-kubectl-patch-command}
594594

595-
`kubectl patch` 命令使用 YAML 或 JSON。它可以接受以文件形式提供的补丁,也可以
596-
接受直接在命令行中给出的补丁。
595+
`kubectl patch` 命令使用 YAML 或 JSON。它可以接受以文件形式提供的补丁,也可以接受直接在命令行中给出的补丁。
597596

598597
<!--
599598
Create a file named `patch-file.json` that has this content:
@@ -654,17 +653,13 @@ and
654653
[`kubectl scale`](/docs/reference/generated/kubectl/kubectl-commands/#scale)
655654
[`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands/#apply)
656655

657-
658-
<!--
659656
{{< note >}}
657+
<!--
660658
Strategic merge patch is not supported for custom resources.
661-
{{< /note >}}
662659
-->
663-
{{< note >}}
664660
定制资源不支持策略性合并 patch。
665661
{{< /note >}}
666662

667-
668663
## {{% heading "whatsnext" %}}
669664

670665
<!--
@@ -675,6 +670,6 @@ Strategic merge patch is not supported for custom resources.
675670
-->
676671
* [Kubernetes 对象管理](/zh-cn/docs/concepts/overview/working-with-objects/object-management/)
677672
* [使用指令式命令管理 Kubernetes 对象](/zh-cn/docs/tasks/manage-kubernetes-objects/imperative-command/)
678-
* [使用配置文件执行 Kubernetes 对象的指令式管理](/zh-cn/docs/tasks/manage-kubernetes-objects/imperative-config)
673+
* [使用配置文件对 Kubernetes 对象进行命令式管理](/zh-cn/docs/tasks/manage-kubernetes-objects/imperative-config/)
679674
* [使用配置文件对 Kubernetes 对象进行声明式管理](/zh-cn/docs/tasks/manage-kubernetes-objects/declarative-config/)
680675

0 commit comments

Comments
 (0)