Skip to content

Commit bb8912e

Browse files
authored
Merge pull request #35911 from windsonsea/kustyhf
[zh-cn] resync kustomization.md
2 parents 9b9cce9 + 8ca4b81 commit bb8912e

File tree

1 file changed

+29
-51
lines changed

1 file changed

+29
-51
lines changed

content/zh-cn/docs/tasks/manage-kubernetes-objects/kustomization.md

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ kubectl kustomize <kustomization_directory>
3434
<!--
3535
To apply those Resources, run `kubectl apply` with `- -kustomize` or `-k` flag:
3636
-->
37-
要应用这些资源,使用参数 `--kustomize``-k` 标志来执行 `kubectl apply`
37+
要应用这些资源,使用 `--kustomize``-k` 参数来执行 `kubectl apply`
3838

3939
```shell
4040
kubectl apply -k <kustomization_directory>
@@ -45,7 +45,7 @@ kubectl apply -k <kustomization_directory>
4545
<!--
4646
Install [`kubectl`](/docs/tasks/tools/).
4747
-->
48-
安装 [`kubectl`](/zh-cn/docs/tasks/tools/).
48+
安装 [`kubectl`](/zh-cn/docs/tasks/tools/)
4949

5050
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
5151

@@ -62,8 +62,7 @@ Kustomize is a tool for customizing Kubernetes configurations. It has the follow
6262
-->
6363
## Kustomize 概述 {#overview-of-kustomize}
6464

65-
Kustomize 是一个用来定制 Kubernetes 配置的工具。它提供以下功能特性来管理
66-
应用配置文件:
65+
Kustomize 是一个用来定制 Kubernetes 配置的工具。它提供以下功能特性来管理应用配置文件:
6766

6867
* 从其他来源生成资源
6968
* 为资源设置贯穿性(Cross-Cutting)字段
@@ -78,10 +77,8 @@ Kustomize has `secretGenerator` and `configMapGenerator`, which generate Secret
7877
### 生成资源 {#generating-resources}
7978

8079
ConfigMap 和 Secret 包含其他 Kubernetes 对象(如 Pod)所需要的配置或敏感数据。
81-
ConfigMap 或 Secret 中数据的来源往往是集群外部,例如某个 `.properties`
82-
文件或者 SSH 密钥文件。
83-
Kustomize 提供 `secretGenerator``configMapGenerator`,可以基于文件或字面
84-
值来生成 Secret 和 ConfigMap。
80+
ConfigMap 或 Secret 中数据的来源往往是集群外部,例如某个 `.properties` 文件或者 SSH 密钥文件。
81+
Kustomize 提供 `secretGenerator``configMapGenerator`,可以基于文件或字面值来生成 Secret 和 ConfigMap。
8582

8683
<!--
8784
#### configMapGenerator
@@ -133,28 +130,16 @@ metadata:
133130
```
134131
135132
<!--
136-
To generate a ConfigMap from an env file, add an entry to the `envs` list in `configMapGenerator`. This can also be used to set values from local environment variables by omitting the `=` and the value.
137-
-->
138-
要从 env 文件生成 ConfigMap,请在 `configMapGenerator` 中的 `envs` 列表中添加一个条目。
139-
这也可以用于通过省略 `=` 和值来设置本地环境变量的值。
140-
141-
<!--
142-
It's recommended to use the local environment variable population functionality sparingly - an overlay with a patch is often more maintainable. Setting values from the environment may be useful when they cannot easily be predicted, such as a git SHA.
143-
-->
144-
建议谨慎使用本地环境变量填充功能 —— 用补丁覆盖通常更易于维护。
145-
当无法轻松预测变量的值时,从环境中设置值可能很有用,例如 git SHA。
146-
147-
<!--
133+
To generate a ConfigMap from an env file, add an entry to the `envs` list in `configMapGenerator`.
148134
Here is an example of generating a ConfigMap with a data item from a `.env` file:
149135
-->
136+
要从 env 文件生成 ConfigMap,请在 `configMapGenerator` 中的 `envs` 列表中添加一个条目。
150137
下面是一个用来自 `.env` 文件的数据生成 ConfigMap 的例子:
151138

152139
```shell
153140
# 创建一个 .env 文件
154-
# BAZ 将使用本地环境变量 $BAZ 的取值填充
155141
cat <<EOF >.env
156142
FOO=Bar
157-
BAZ
158143
EOF
159144
160145
cat <<EOF >./kustomization.yaml
@@ -171,7 +156,7 @@ The generated ConfigMap can be examined with the following command:
171156
可以使用以下命令检查生成的 ConfigMap:
172157

173158
```shell
174-
BAZ=Qux kubectl kustomize ./
159+
kubectl kustomize ./
175160
```
176161

177162
<!--
@@ -182,11 +167,10 @@ The generated ConfigMap is:
182167
```yaml
183168
apiVersion: v1
184169
data:
185-
BAZ: Qux
186170
FOO: Bar
187171
kind: ConfigMap
188172
metadata:
189-
name: example-configmap-1-892ghb99c8
173+
name: example-configmap-1-42cfbf598f
190174
```
191175

192176
<!--
@@ -201,8 +185,8 @@ Each variable in the `.env` file becomes a separate key in the ConfigMap that yo
201185
ConfigMaps can also be generated from literal key-value pairs. To generate a ConfigMap from a literal key-value pair, add an entry to the `literals` list in configMapGenerator. Here is an example of generating a ConfigMap with a data item from a key-value pair:
202186
-->
203187
ConfigMap 也可基于字面的键值偶对来生成。要基于键值偶对来生成 ConfigMap,
204-
在 `configMapGenerator` 的 `literals` 列表中添加表项。下面是一个例子,展示
205-
如何使用键值偶对中的数据条目来生成 ConfigMap 对象:
188+
在 `configMapGenerator` 的 `literals` 列表中添加表项。下面是一个例子,
189+
展示如何使用键值偶对中的数据条目来生成 ConfigMap 对象:
206190

207191
```shell
208192
cat <<EOF >./kustomization.yaml
@@ -414,7 +398,7 @@ type: Opaque
414398
<!--
415399
Like ConfigMaps, generated Secrets can be used in Deployments by referring to the name of the secretGenerator:
416400
-->
417-
ConfigMaps 一样,生成的 Secrets 可以通过引用 secretGenerator 的名称在部署中使用
401+
ConfigMap 一样,生成的 Secret 可以通过引用 secretGenerator 的名称在 Deployment 中使用
418402

419403
```shell
420404
# 创建一个 password.txt 文件
@@ -616,10 +600,9 @@ Here is an example of an NGINX application comprised of a Deployment and a Servi
616600
-->
617601
#### 组织 {#composing}
618602

619-
Kustomize 支持组合不同的资源。`kustomization.yaml` 文件的 `resources` 字段
620-
定义配置中要包含的资源列表。你可以将 `resources` 列表中的路径设置为资源配置文件
621-
的路径。下面是由 Deployment 和 Service 构成的 NGINX 应用的示例:
622-
603+
Kustomize 支持组合不同的资源。`kustomization.yaml` 文件的 `resources` 字段定义配置中要包含的资源列表。
604+
你可以将 `resources` 列表中的路径设置为资源配置文件的路径。
605+
下面是由 Deployment 和 Service 构成的 NGINX 应用的示例:
623606

624607
```shell
625608
# 创建 deployment.yaml 文件
@@ -683,13 +666,12 @@ mechanisms through `patchesStrategicMerge` and `patchesJson6902`. `patchesStrate
683666
#### 定制 {#customizing}
684667

685668
补丁文件(Patches)可以用来对资源执行不同的定制。
686-
Kustomize 通过 `patchesStrategicMerge` 和 `patchesJson6902` 支持不同的打补丁
687-
机制。`patchesStrategicMerge` 的内容是一个文件路径的列表,其中每个文件都应可解析为
669+
Kustomize 通过 `patchesStrategicMerge` 和 `patchesJson6902` 支持不同的打补丁机制。
670+
`patchesStrategicMerge` 的内容是一个文件路径的列表,其中每个文件都应可解析为
688671
[策略性合并补丁(Strategic Merge Patch)](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md)。
689672
补丁文件中的名称必须与已经加载的资源的名称匹配。
690673
建议构造规模较小的、仅做一件事情的补丁。
691-
例如,构造一个补丁来增加 Deployment
692-
的副本个数;构造另外一个补丁来设置内存限制。
674+
例如,构造一个补丁来增加 Deployment 的副本个数;构造另外一个补丁来设置内存限制。
693675

694676
```shell
695677
# 创建 deployment.yaml 文件
@@ -788,11 +770,10 @@ specified in `kustomization.yaml`. For example, increasing the replica number of
788770
through `patchesJson6902`.
789771
-->
790772
并非所有资源或者字段都支持策略性合并补丁。为了支持对任何资源的任何字段进行修改,
791-
Kustomize 提供通过 `patchesJson6902` 来应用 [JSON 补丁](https://tools.ietf.org/html/rfc6902)
792-
的能力。为了给 JSON 补丁找到正确的资源,需要在 `kustomization.yaml` 文件中指定资源的
793-
组(group)、版本(version)、类别(kind)和名称(name)。
794-
例如,为某 Deployment 对象增加副本个数的操作也可以通过 `patchesJson6902`
795-
来完成:
773+
Kustomize 提供通过 `patchesJson6902` 来应用 [JSON 补丁](https://tools.ietf.org/html/rfc6902)的能力。
774+
为了给 JSON 补丁找到正确的资源,需要在 `kustomization.yaml` 文件中指定资源的组(group)、
775+
版本(version)、类别(kind)和名称(name)。
776+
例如,为某 Deployment 对象增加副本个数的操作也可以通过 `patchesJson6902` 来完成:
796777

797778
```shell
798779
# 创建一个 deployment.yaml 文件
@@ -871,10 +852,8 @@ spec:
871852
In addition to patches, Kustomize also offers customizing container images or injecting field values from other objects into containers
872853
without creating patches. For example, you can change the image used inside containers by specifying the new image in `images` field in `kustomization.yaml`.
873854
-->
874-
除了补丁之外,Kustomize 还提供定制容器镜像或者将其他对象的字段值注入到容器
875-
中的能力,并且不需要创建补丁。
876-
例如,你可以通过在 `kustomization.yaml` 文件的 `images` 字段设置新的镜像来
877-
更改容器中使用的镜像。
855+
除了补丁之外,Kustomize 还提供定制容器镜像或者将其他对象的字段值注入到容器中的能力,并且不需要创建补丁。
856+
例如,你可以通过在 `kustomization.yaml` 文件的 `images` 字段设置新的镜像来更改容器中使用的镜像。
878857

879858
```shell
880859
cat <<EOF > deployment.yaml
@@ -1108,8 +1087,8 @@ EOF
11081087
This base can be used in multiple overlays. You can add different `namePrefix` or other cross-cutting fields
11091088
in different overlays. Here are two overlays using the same base.
11101089
-->
1111-
此基准可在多个覆盖中使用。你可以在不同的覆盖中添加不同的 `namePrefix`
1112-
其他贯穿性字段。下面是两个使用同一基准的覆盖:
1090+
此基准可在多个覆盖中使用。你可以在不同的覆盖中添加不同的 `namePrefix` 或其他贯穿性字段。
1091+
下面是两个使用同一基准的覆盖:
11131092

11141093
```shell
11151094
mkdir dev
@@ -1145,7 +1124,7 @@ kubectl apply -k <kustomization 目录>/
11451124
<!--
11461125
Given the following `kustomization.yaml`,
11471126
-->
1148-
假定使用下面的 `kustomization.yaml`
1127+
假定使用下面的 `kustomization.yaml`
11491128

11501129
```shell
11511130
# 创建 deployment.yaml 文件
@@ -1209,8 +1188,7 @@ kubectl describe -k ./
12091188
<!--
12101189
Run the following command to compare the Deployment object `dev-my-nginx` against the state that the cluster would be in if the manifest was applied:
12111190
-->
1212-
执行下面的命令来比较 Deployment 对象 `dev-my-nginx` 与清单被应用之后
1213-
集群将处于的状态:
1191+
执行下面的命令来比较 Deployment 对象 `dev-my-nginx` 与清单被应用之后集群将处于的状态:
12141192

12151193
```shell
12161194
kubectl diff -k ./
@@ -1231,7 +1209,7 @@ deployment.apps "dev-my-nginx" deleted
12311209
<!--
12321210
## Kustomize Feature List
12331211
-->
1234-
## Kustomize 功能特性列表
1212+
## Kustomize 功能特性列表 {#kustomize-feature-list}
12351213

12361214
<!--
12371215
| Field | Type | Explanation |

0 commit comments

Comments
 (0)