Skip to content

Commit 8ff47de

Browse files
committed
[zh] Sync config-pod-configmap also fix unknown field
1. Sync upstream content and format 2. Add code block with EN comment 3. Fix ZH kustomization.yaml `labels` unknown field. Remove too long code comments don't needed.
1 parent 1483479 commit 8ff47de

File tree

1 file changed

+101
-13
lines changed

1 file changed

+101
-13
lines changed

content/zh-cn/docs/tasks/configure-pod-container/configure-pod-configmap.md

Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ ConfigMap 是 Kubernetes 的一种机制,可让你将配置数据注入到应
3030
<!--
3131
The ConfigMap concept allow you to decouple configuration artifacts from image content to
3232
keep containerized applications portable. For example, you can download and run the same
33-
{{< glossary_tooltip text="container image" term_id="image" >}} to spin up containers for the purposes of local development, system test, or running a live end-user workload.
33+
{{< glossary_tooltip text="container image" term_id="image" >}} to spin up containers for
34+
the purposes of local development, system test, or running a live end-user workload.
3435
-->
3536
ConfigMap 概念允许你将配置清单与镜像内容分离,以保持容器化的应用程序的可移植性。
3637
例如,你可以下载并运行相同的{{< glossary_tooltip text="容器镜像" term_id="image" >}}来启动容器,
@@ -133,8 +134,10 @@ symlinks, devices, pipes, and more).
133134

134135
{{< note >}}
135136
<!--
136-
Each filename being used for ConfigMap creation must consist of only acceptable characters, which are: letters (`A` to `Z` and `a` to `z`), digits (`0` to `9`), '-', '_', or '.'.
137-
If you use `kubectl create configmap` with a directory where any of the file names contains an unacceptable character, the `kubectl` command may fail.
137+
Each filename being used for ConfigMap creation must consist of only acceptable characters,
138+
which are: letters (`A` to `Z` and `a` to `z`), digits (`0` to `9`), '-', '_', or '.'.
139+
If you use `kubectl create configmap` with a directory where any of the file names contains
140+
an unacceptable character, the `kubectl` command may fail.
138141
-->
139142
用于创建 ConfigMap 的每个文件名必须由可接受的字符组成,即:字母(`A``Z`
140143
`a``z`)、数字(`0``9`)、'-'、'_'或'.'。
@@ -162,6 +165,16 @@ Now, download the sample configuration and create the ConfigMap:
162165
-->
163166
现在,下载示例的配置并创建 ConfigMap:
164167

168+
<!--
169+
```shell
170+
# Download the sample files into `configure-pod-container/configmap/` directory
171+
wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties
172+
wget https://kubernetes.io/examples/configmap/ui.properties -O configure-pod-container/configmap/ui.properties
173+
174+
# Create the ConfigMap
175+
kubectl create configmap game-config --from-file=configure-pod-container/configmap/
176+
```
177+
-->
165178
```shell
166179
# 将示例文件下载到 `configure-pod-container/configmap/` 目录
167180
wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties
@@ -360,6 +373,28 @@ Use the option `--from-env-file` to create a ConfigMap from an env-file, for exa
360373
-->
361374
使用 `--from-env-file` 选项基于 env 文件创建 ConfigMap,例如:
362375

376+
<!--
377+
```shell
378+
# Env-files contain a list of environment variables.
379+
# These syntax rules apply:
380+
# Each line in an env file has to be in VAR=VAL format.
381+
# Lines beginning with # (i.e. comments) are ignored.
382+
# Blank lines are ignored.
383+
# There is no special handling of quotation marks (i.e. they will be part of the ConfigMap value)).
384+
385+
# Download the sample files into `configure-pod-container/configmap/` directory
386+
wget https://kubernetes.io/examples/configmap/game-env-file.properties -O configure-pod-container/configmap/game-env-file.properties
387+
wget https://kubernetes.io/examples/configmap/ui-env-file.properties -O configure-pod-container/configmap/ui-env-file.properties
388+
389+
# The env-file `game-env-file.properties` looks like below
390+
cat configure-pod-container/configmap/game-env-file.properties
391+
enemies=aliens
392+
lives=3
393+
allowed="true"
394+
395+
# This comment and the empty line above it are ignored
396+
```
397+
-->
363398
```shell
364399
# Env 文件包含环境变量列表。其中适用以下语法规则:
365400
# 这些语法规则适用:
@@ -378,7 +413,7 @@ enemies=aliens
378413
lives=3
379414
allowed="true"
380415

381-
# This comment and the empty line above it are ignored
416+
# 此注释和上方的空行将被忽略
382417
```
383418

384419
```shell
@@ -595,13 +630,17 @@ For example, to generate a ConfigMap from files `configure-pod-container/configm
595630
例如,要基于 `configure-pod-container/configmap/game.properties`
596631
文件生成一个 ConfigMap:
597632

633+
<!--
634+
# Create a kustomization.yaml file with ConfigMapGenerator
635+
-->
598636
```shell
599637
# 创建包含 ConfigMapGenerator 的 kustomization.yaml 文件
600638
cat <<EOF >./kustomization.yaml
601639
configMapGenerator:
602640
- name: game-config-4
603-
labels:
604-
game-config: config-4
641+
options:
642+
labels:
643+
game-config: config-4
605644
files:
606645
- configure-pod-container/configmap/game.properties
607646
EOF
@@ -680,13 +719,28 @@ with the key `game-special-key`
680719
例如,从 `configure-pod-container/configmap/game.properties` 文件生成 ConfigMap,
681720
但使用 `game-special-key` 作为键名:
682721

722+
<!--
723+
```shell
724+
# Create a kustomization.yaml file with ConfigMapGenerator
725+
cat <<EOF >./kustomization.yaml
726+
configMapGenerator:
727+
- name: game-config-5
728+
options:
729+
labels:
730+
game-config: config-5
731+
files:
732+
- game-special-key=configure-pod-container/configmap/game.properties
733+
EOF
734+
```
735+
-->
683736
```shell
684737
# 创建包含 ConfigMapGenerator 的 kustomization.yaml 文件
685738
cat <<EOF >./kustomization.yaml
686739
configMapGenerator:
687740
- name: game-config-5
688-
labels:
689-
game-config: config-5
741+
options:
742+
labels:
743+
game-config: config-5
690744
files:
691745
- game-special-key=configure-pod-container/configmap/game.properties
692746
EOF
@@ -719,6 +773,9 @@ this, you can specify the `ConfigMap` generator. Create (or replace)
719773
为了实现这一点,你可以配置 `ConfigMap` 生成器。
720774
创建(或替换)`kustomization.yaml`,使其具有以下内容。
721775

776+
<!--
777+
# kustomization.yaml contents for creating a ConfigMap from literals
778+
-->
722779
```yaml
723780
---
724781
# 基于字面创建 ConfigMap 的 kustomization.yaml 内容
@@ -784,7 +841,8 @@ section, and learn how to use these objects with Pods.
784841
```
785842
786843
<!--
787-
2. Assign the `special.how` value defined in the ConfigMap to the `SPECIAL_LEVEL_KEY` environment variable in the Pod specification.
844+
2. Assign the `special.how` value defined in the ConfigMap to the `SPECIAL_LEVEL_KEY`
845+
environment variable in the Pod specification.
788846
-->
789847
2. 将 ConfigMap 中定义的 `special.how` 赋值给 Pod 规约中的 `SPECIAL_LEVEL_KEY` 环境变量。
790848
@@ -964,7 +1022,7 @@ kubectl delete pod dapi-test-pod --now
9641022
## Add ConfigMap data to a Volume
9651023

9661024
As explained in [Create ConfigMaps from files](#create-configmaps-from-files), when you create
967-
a ConfigMap using ``--from-file``, the filename becomes a key stored in the `data` section of
1025+
a ConfigMap using `--from-file`, the filename becomes a key stored in the `data` section of
9681026
the ConfigMap. The file contents become the key's value.
9691027
-->
9701028
## 将 ConfigMap 数据添加到一个卷中 {#add-configmap-data-to-a-volume}
@@ -1027,7 +1085,8 @@ SPECIAL_TYPE
10271085
10281086
<!--
10291087
Text data is exposed as files using the UTF-8 character encoding. To use some other
1030-
character encoding, use `binaryData` (see [ConfigMap object](/docs/concepts/configuration/configmap/#configmap-object) for more details).
1088+
character encoding, use `binaryData`
1089+
(see [ConfigMap object](/docs/concepts/configuration/configmap/#configmap-object) for more details).
10311090
-->
10321091
文本数据会展现为 UTF-8 字符编码的文件。如果使用其他字符编码,
10331092
可以使用 `binaryData`(详情参阅 [ConfigMap 对象](/zh-cn/docs/concepts/configuration/configmap/#configmap-object))。
@@ -1117,7 +1176,7 @@ guide explains the syntax.
11171176
<!--
11181177
### Optional references
11191178

1120-
A ConfigMap reference may be marked _optional_. If the ConfigMap is non-existent, the mounted
1179+
A ConfigMap reference may be marked _optional_. If the ConfigMap is non-existent, the mounted
11211180
volume will be empty. If the ConfigMap exists, but the referenced key is non-existent, the path
11221181
will be absent beneath the mount point. See [Optional ConfigMaps](#optional-configmaps) for more
11231182
details.
@@ -1157,7 +1216,8 @@ Kubelet 在每次定期同步时都会检查所挂载的 ConfigMap 是否是最
11571216
11581217
{{< note >}}
11591218
<!--
1160-
A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes/#using-subpath) volume will not receive ConfigMap updates.
1219+
A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes/#using-subpath)
1220+
volume will not receive ConfigMap updates.
11611221
-->
11621222
使用 ConfigMap 作为 [subPath](/zh-cn/docs/concepts/storage/volumes/#using-subpath)
11631223
卷的容器将不会收到 ConfigMap 更新。
@@ -1204,6 +1264,25 @@ ConfigMap 的 `data` 字段包含配置数据。如下例所示,它可以简
12041264
(如用 `--from-literal` 的单个属性定义)或复杂
12051265
(如用 `--from-file` 的配置文件或 JSON blob 定义)。
12061266
1267+
<!--
1268+
```yaml
1269+
apiVersion: v1
1270+
kind: ConfigMap
1271+
metadata:
1272+
creationTimestamp: 2016-02-18T19:14:38Z
1273+
name: example-config
1274+
namespace: default
1275+
data:
1276+
# example of a simple property defined using --from-literal
1277+
example.property.1: hello
1278+
example.property.2: world
1279+
# example of a complex property defined using --from-file
1280+
example.property.file: |-
1281+
property.1=value-1
1282+
property.2=value-2
1283+
property.3=value-3
1284+
```
1285+
-->
12071286
```yaml
12081287
apiVersion: v1
12091288
kind: ConfigMap
@@ -1264,6 +1343,9 @@ as optional:
12641343
-->
12651344
例如,以下 Pod 规约将 ConfigMap 中的环境变量标记为可选:
12661345

1346+
<!--
1347+
optional: true # mark the variable as optional
1348+
-->
12671349
```yaml
12681350
apiVersion: v1
12691351
kind: Pod
@@ -1305,6 +1387,9 @@ example, the following Pod specification marks a volume that references a Config
13051387
此时 Kubernetes 将总是为卷创建挂载路径,即使引用的 ConfigMap 或键不存在。
13061388
例如,以下 Pod 规约将所引用得 ConfigMap 的卷标记为可选:
13071389

1390+
<!--
1391+
optional: true # mark the source ConfigMap as optional
1392+
-->
13081393
```yaml
13091394
apiVersion: v1
13101395
kind: Pod
@@ -1390,6 +1475,9 @@ Delete the ConfigMaps and Pods that you made:
13901475
-->
13911476
删除你创建那些的 ConfigMap 和 Pod:
13921477

1478+
<!--
1479+
# You might already have removed the next set
1480+
-->
13931481
```bash
13941482
kubectl delete configmaps/game-config configmaps/game-config-2 configmaps/game-config-3 \
13951483
configmaps/game-config-env-file

0 commit comments

Comments
 (0)