Skip to content

Commit 96c83e7

Browse files
authored
Merge pull request #28023 from CaoDonghui123/fix3
[zh]Resync tasks files[6]
2 parents 6803d4d + 1b01510 commit 96c83e7

File tree

1 file changed

+219
-14
lines changed

1 file changed

+219
-14
lines changed

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

Lines changed: 219 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ kubectl apply -k <kustomization_directory>
4343
## {{% heading "prerequisites" %}}
4444

4545
<!--
46-
Install [`kubectl`](/docs/tasks/tools/install-kubectl/).
46+
Install [`kubectl`](/docs/tasks/tools/).
4747
-->
48-
安装 [`kubectl`](/zh/docs/tasks/tools/install-kubectl/).
48+
安装 [`kubectl`](/zh/docs/tasks/tools/).
4949

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

@@ -132,6 +132,57 @@ metadata:
132132
name: example-configmap-1-8mbdf7882g
133133
```
134134
135+
<!--
136+
To generate a ConfigMap from an env file, add an entry to the `envs` list in `configMapGenerator`. Here is an example of generating a ConfigMap with a data item from a `.env` file:
137+
-->
138+
要从 env 文件生成 ConfigMap,请在 `configMapGenerator` 中的 `envs` 列表中添加一个条目。
139+
下面是一个用来自 `.env` 文件的数据生成 ConfigMap 的例子:
140+
141+
```shell
142+
# 创建一个 .env 文件
143+
cat <<EOF >.env
144+
FOO=Bar
145+
EOF
146+
147+
cat <<EOF >./kustomization.yaml
148+
configMapGenerator:
149+
- name: example-configmap-1
150+
envs:
151+
- .env
152+
EOF
153+
```
154+
155+
<!--
156+
The generated ConfigMap can be examined with the following command:
157+
-->
158+
可以使用以下命令检查生成的 ConfigMap:
159+
160+
```shell
161+
kubectl kustomize ./
162+
```
163+
164+
<!--
165+
The generated ConfigMap is:
166+
-->
167+
生成的 ConfigMap 为:
168+
169+
```yaml
170+
apiVersion: v1
171+
data:
172+
FOO=Bar
173+
kind: ConfigMap
174+
metadata:
175+
name: example-configmap-1-8mbdf7882g
176+
```
177+
178+
<!--
179+
Each variable in the `.env` file becomes a separate key in the ConfigMap that you generate. This is different from the previous example which embeds a file named `.properties` (and all its entries) as the value for a single key.
180+
-->
181+
{{< note >}}
182+
`.env` 文件中的每个变量在生成的 ConfigMap 中成为一个单独的键。
183+
这与之前的示例不同,前一个示例将一个名为 `.properties` 的文件(及其所有条目)嵌入到同一个键的值中。
184+
{{< /note >}}
185+
135186
<!--
136187
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:
137188
-->
@@ -171,6 +222,110 @@ metadata:
171222
name: example-configmap-2-g2hdhfc6tk
172223
```
173224

225+
<!--
226+
To use a generated ConfigMap in a Deployment, reference it by the name of the configMapGenerator. Kustomize will automatically replace this name with the generated name.
227+
228+
This is an example deployment that uses a generated ConfigMap:
229+
-->
230+
要在 Deployment 中使用生成的 ConfigMap,使用 configMapGenerator 的名称对其进行引用。
231+
Kustomize 将自动使用生成的名称替换该名称。
232+
233+
这是使用生成的 ConfigMap 的 deployment 示例:
234+
235+
```yaml
236+
# 创建一个 application.properties 文件
237+
cat <<EOF >application.properties
238+
FOO=Bar
239+
EOF
240+
241+
cat <<EOF >deployment.yaml
242+
apiVersion: apps/v1
243+
kind: Deployment
244+
metadata:
245+
name: my-app
246+
labels:
247+
app: my-app
248+
spec:
249+
selector:
250+
matchLabels:
251+
app: my-app
252+
template:
253+
metadata:
254+
labels:
255+
app: my-app
256+
spec:
257+
containers:
258+
- name: app
259+
image: my-app
260+
volumeMount:
261+
- name: config
262+
mountPath: /config
263+
volumes:
264+
- name: config
265+
configMap:
266+
name: example-configmap-1
267+
EOF
268+
269+
cat <<EOF >./kustomization.yaml
270+
resources:
271+
- deployment.yaml
272+
configMapGenerator:
273+
- name: example-configmap-1
274+
files:
275+
- application.properties
276+
EOF
277+
```
278+
279+
<!--
280+
Generate the ConfigMap and Deployment:
281+
-->
282+
生成 ConfigMap 和 Deployment:
283+
284+
```shell
285+
kubectl kustomize ./
286+
```
287+
288+
<!--
289+
The generated Deployment will refer to the generated ConfigMap by name:
290+
-->
291+
生成的 Deployment 将通过名称引用生成的 ConfigMap:
292+
293+
```yaml
294+
apiVersion: v1
295+
data:
296+
application.properties: |
297+
FOO=Bar
298+
kind: ConfigMap
299+
metadata:
300+
name: example-configmap-1-g4hk9g2ff8
301+
---
302+
apiVersion: apps/v1
303+
kind: Deployment
304+
metadata:
305+
labels:
306+
app: my-app
307+
name: my-app
308+
spec:
309+
selector:
310+
matchLabels:
311+
app: my-app
312+
template:
313+
metadata:
314+
labels:
315+
app: my-app
316+
spec:
317+
containers:
318+
- image: my-app
319+
name: app
320+
volumeMount:
321+
- mountPath: /config
322+
name: config
323+
volumes:
324+
- configMap:
325+
name: example-configmap-1-g4hk9g2ff8
326+
name: config
327+
```
328+
174329
#### secretGenerator
175330

176331
<!--
@@ -242,6 +397,56 @@ metadata:
242397
type: Opaque
243398
```
244399

400+
<!--
401+
Like ConfigMaps, generated Secrets can be used in Deployments by refering to the name of the secretGenerator:
402+
-->
403+
与 ConfigMaps 一样,生成的 Secrets 可以通过引用 secretGenerator 的名称在部署中使用:
404+
405+
```shell
406+
# 创建一个 password.txt 文件
407+
cat <<EOF >./password.txt
408+
username=admin
409+
password=secret
410+
EOF
411+
412+
cat <<EOF >deployment.yaml
413+
apiVersion: apps/v1
414+
kind: Deployment
415+
metadata:
416+
name: my-app
417+
labels:
418+
app: my-app
419+
spec:
420+
selector:
421+
matchLabels:
422+
app: my-app
423+
template:
424+
metadata:
425+
labels:
426+
app: my-app
427+
spec:
428+
containers:
429+
- name: app
430+
image: my-app
431+
volumeMount:
432+
- name: password
433+
mountPath: /secrets
434+
volumes:
435+
- name: password
436+
secret:
437+
secretName: example-secret-1
438+
EOF
439+
440+
cat <<EOF >./kustomization.yaml
441+
resources:
442+
- deployment.yaml
443+
secretGenerator:
444+
- name: example-secret-1
445+
files:
446+
- password.txt
447+
EOF
448+
```
449+
245450
#### generatorOptions
246451

247452
<!--
@@ -1023,14 +1228,14 @@ deployment.apps "dev-my-nginx" deleted
10231228
| commonLabels | map[string]string | labels to add to all resources and selectors |
10241229
| commonAnnotations | map[string]string | annotations to add to all resources |
10251230
| resources | []string | each entry in this list must resolve to an existing resource configuration file |
1026-
| configmapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/kustomization.go#L99) | Each entry in this list generates a ConfigMap |
1027-
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/kustomization.go#L106) | Each entry in this list generates a Secret |
1028-
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/kustomization.go#L109) | Modify behaviors of all ConfigMap and Secret generator |
1231+
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | Each entry in this list generates a ConfigMap |
1232+
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | Each entry in this list generates a Secret |
1233+
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | Modify behaviors of all ConfigMap and Secret generator |
10291234
| bases | []string | Each entry in this list should resolve to a directory containing a kustomization.yaml file |
10301235
| patchesStrategicMerge | []string | Each entry in this list should resolve a strategic merge patch of a Kubernetes object |
1031-
| patchesJson6902 | [][Json6902](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/patchjson6902.go#L8) | Each entry in this list should resolve to a Kubernetes object and a Json Patch |
1032-
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L31) | Each entry is to capture text from one resource's field |
1033-
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/tree/master/api/types/image.go#L23) | Each entry is to modify the name, tags and/or digest for one image without creating patches |
1236+
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | Each entry in this list should resolve to a Kubernetes object and a Json Patch |
1237+
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | Each entry is to capture text from one resource's field |
1238+
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | Each entry is to modify the name, tags and/or digest for one image without creating patches |
10341239
| configurations | []string | Each entry in this list should resolve to a file containing [Kustomize transformer configurations](https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs) |
10351240
| crds | []string | Each entry in this list should resolve to an OpenAPI definition file for Kubernetes types |
10361241
-->
@@ -1043,14 +1248,14 @@ deployment.apps "dev-my-nginx" deleted
10431248
| commonLabels | map[string]string | 要添加到所有资源和选择算符的标签 |
10441249
| commonAnnotations | map[string]string | 要添加到所有资源的注解 |
10451250
| resources | []string | 列表中的每个条目都必须能够解析为现有的资源配置文件 |
1046-
| configmapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/kustomization.go#L99) | 列表中的每个条目都会生成一个 ConfigMap |
1047-
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/kustomization.go#L106) | 列表中的每个条目都会生成一个 Secret |
1048-
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/kustomization.go#L109) | 更改所有 ConfigMap 和 Secret 生成器的行为 |
1251+
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | 列表中的每个条目都会生成一个 ConfigMap |
1252+
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | 列表中的每个条目都会生成一个 Secret |
1253+
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | 更改所有 ConfigMap 和 Secret 生成器的行为 |
10491254
| bases | []string | 列表中每个条目都应能解析为一个包含 kustomization.yaml 文件的目录 |
10501255
| patchesStrategicMerge | []string | 列表中每个条目都能解析为某 Kubernetes 对象的策略性合并补丁 |
1051-
| patchesJson6902 | [][Json6902](https://github.com/kubernetes-sigs/kustomize/blob/release-kustomize-v4.0/api/types/patchjson6902.go#L8) | 列表中每个条目都能解析为一个 Kubernetes 对象和一个 JSON 补丁 |
1052-
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L31) | 每个条目用来从某资源的字段来析取文字 |
1053-
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/tree/master/api/types/image.go#L23) | 每个条目都用来更改镜像的名称、标记与/或摘要,不必生成补丁 |
1256+
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | 列表中每个条目都能解析为一个 Kubernetes 对象和一个 JSON 补丁 |
1257+
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | 每个条目用来从某资源的字段来析取文字 |
1258+
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | 每个条目都用来更改镜像的名称、标记与/或摘要,不必生成补丁 |
10541259
| configurations | []string | 列表中每个条目都应能解析为一个包含 [Kustomize 转换器配置](https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs) 的文件 |
10551260
| crds | []string | 列表中每个条目都赢能够解析为 Kubernetes 类别的 OpenAPI 定义文件 |
10561261

0 commit comments

Comments
 (0)