You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many applications rely on configuration which is used during either application initialization or runtime.
21
21
Most of the times there is a requirement to adjust values assigned to configuration parameters.
22
-
ConfigMaps is the kubernetes way to inject application pods with configuration data.
22
+
ConfigMaps are the Kubernetes way to inject application pods with configuration data.
23
23
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. This page provides a series of usage examples demonstrating how to create ConfigMaps and configure Pods using data stored in ConfigMaps.
24
24
-->
25
25
很多应用在其初始化或运行期间要依赖一些配置信息。大多数时候,
@@ -85,19 +85,13 @@ You can use [`kubectl describe`](/docs/reference/generated/kubectl/kubectl-comma
85
85
[`kubectl get`](/docs/reference/generated/kubectl/kubectl-commands/#get) to retrieve information
You can use `kubectl create configmap` to create a ConfigMap from multiple
95
-
files in the same directory.
96
-
When you are creating a ConfigMap based on a directory, kubectl identifies
97
-
files whose basename is a valid key in the directory and packages each of
98
-
those files into the new ConfigMap. Any directory entries except regular files
99
-
are ignored (e.g. subdirectories, symlinks, devices, pipes, etc).
100
-
94
+
You can use `kubectl create configmap` to create a ConfigMap from multiple files in the same directory. When you are creating a ConfigMap based on a directory, kubectl identifies files whose basename is a valid key in the directory and packages each of those files into the new ConfigMap. Any directory entries except regular files are ignored (e.g. subdirectories, symlinks, devices, pipes, etc).
The above command packages each file, in this case, `game.properties` and
139
-
`ui.properties` in the `configure-pod-container/configmap/` directory into the
140
-
game-config ConfigMap. You can display details of the ConfigMap using the
141
-
following command:
132
+
The above command packages each file, in this case, `game.properties` and `ui.properties` in the `configure-pod-container/configmap/` directory into the game-config ConfigMap. You can display details of the ConfigMap using the following command:
A ConfigMap reference may be marked "optional". If the ConfigMap is non-existent, the mounted volume will be empty. If the ConfigMap exists, but the referenced
1063
-
key is non-existent the path will be absent beneath the mount point.
When a mounted ConfigMap is updated, the projected content is eventually updated too. This applies in the case where an optionally referenced ConfigMap comes into
1078
-
existence after a pod has started.
1079
-
-->
1080
-
当某个已被挂载的 ConfigMap 被更新,所投射的内容最终也会被更新。
1081
-
对于 Pod 已经启动之后所引用的、可选的 ConfigMap 才出现的情形,
1082
-
这一动态更新现象也是适用的。
1083
1050
1084
-
<!--
1085
-
Kubelet checks whether the mounted ConfigMap is fresh on every periodic sync. However, it uses its local TTL-based cache for getting the current value of the
1086
-
ConfigMap. As a result, the total delay from the moment when the ConfigMap is updated to the moment when new keys are projected to the pod can be as long as
1087
-
kubelet sync period (1 minute by default) + TTL of ConfigMaps cache (1 minute by default) in kubelet.
# example of a simple property defined using --from-literal
1145
-
example.property.1: hello
1146
-
example.property.2: world
1147
-
# example of a complex property defined using --from-file
1148
-
example.property.file: |-
1149
-
property.1=value-1
1150
-
property.2=value-2
1151
-
property.3=value-3
1152
-
```
1153
-
-->
1084
+
1154
1085
```yaml
1155
1086
apiVersion: v1
1156
1087
kind: ConfigMap
@@ -1172,13 +1103,14 @@ data:
1172
1103
<!--
1173
1104
### Restrictions
1174
1105
1175
-
- You must create a ConfigMapbefore referencing it in a Pod specification (unless you mark the ConfigMap as "optional"). If you reference a ConfigMap that doesn't exist, the Pod won't start. Likewise, references to keys that don't exist in the ConfigMap will prevent the pod from starting.
1106
+
- You must create the `ConfigMap` object before you reference it in a Pod specification. Alternatively, mark the ConfigMap reference as `optional` in the Pod spec (see [Optional ConfigMaps](#optional-configmaps)). If you reference a ConfigMap that doesn't exist and you don't mark the reference as `optional`, the Pod won't start. Similarly, references to keys that don't exist in the ConfigMap will also prevent the Pod from starting, unless you mark the key references as `optional`.
1176
1107
-->
1177
1108
### 限制 {#restrictions}
1178
1109
1179
-
- 在 Pod 规约中引用某个 ConfigMap 之前,必须先创建它(除非将 ConfigMap 标记为
1180
-
“optional(可选)”)。如果引用的 ConfigMap 不存在,则 Pod 将不会启动。
1181
-
同样,引用 ConfigMap 中不存在的主键也会令 Pod 无法启动。
1110
+
- 在 Pod 规约中引用某个 `ConfigMap` 之前,必须先创建这个对象,
1111
+
或者在 Pod 规约中将 ConfigMap 标记为 `optional`(请参阅[可选的 ConfigMaps](#optional-configmaps))。
1112
+
如果所引用的 ConfigMap 不存在,并且没有将应用标记为 `optional` 则 Pod 将无法启动。
1113
+
同样,引用 ConfigMap 中不存在的主键也会令 Pod 无法启动,除非你将 Configmap 标记为 `optional`。
1182
1114
1183
1115
<!--
1184
1116
- If you use `envFrom` to define environment variables from ConfigMaps, keys that are considered invalid will be skipped. The pod will be allowed to start, but the invalid names will be recorded in the event log (`InvalidVariableNames`). The log message lists each skipped key. For example:
You can mark a reference to a ConfigMap as _optional_ in a Pod specification.
1155
+
If the ConfigMap doesn't exist, the configuration for which it provides data in the Pod (e.g. environment variable, mounted volume) will be empty.
1156
+
If the ConfigMap exists, but the referenced key is non-existent the data is also empty.
1157
+
-->
1158
+
你可以在 Pod 规约中将对 ConfigMap 的引用标记为 **可选(optional)**。
1159
+
如果 ConfigMap 不存在,那么它在 Pod 中为其提供数据的配置(例如环境变量、挂载的卷)将为空。
1160
+
如果 ConfigMap 存在,但引用的键不存在,那么数据也是空的。
1161
+
1162
+
<!--
1163
+
For example, the following Pod specification marks an environment variable from a ConfigMap as optional:
1164
+
-->
1165
+
例如,以下 Pod 规约将 ConfigMap 中的环境变量标记为可选:
1166
+
1167
+
```yaml
1168
+
apiVersion: v1
1169
+
kind: Pod
1170
+
metadata:
1171
+
name: dapi-test-pod
1172
+
spec:
1173
+
containers:
1174
+
- name: test-container
1175
+
image: gcr.io/google_containers/busybox
1176
+
command: [ "/bin/sh", "-c", "env" ]
1177
+
env:
1178
+
- name: SPECIAL_LEVEL_KEY
1179
+
valueFrom:
1180
+
configMapKeyRef:
1181
+
name: a-config
1182
+
key: akey
1183
+
optional: true # 将环境变量标记为可选
1184
+
restartPolicy: Never
1185
+
```
1186
+
<!--
1187
+
If you run this pod, and there is no ConfigMap named `a-config`, the output is empty.
1188
+
If you run this pod, and there is a ConfigMap named `a-config` but that ConfigMap doesn't have
1189
+
a key named `akey`, the output is also empty. If you do set a value for `akey` in the `a-config`
1190
+
ConfigMap, this pod prints that value and then terminates.
1191
+
-->
1192
+
当你运行这个 Pod 并且名称为 `a-config` 的 ConfigMap 不存在时,输出空值。
1193
+
当你运行这个 Pod 并且名称为 `a-config` 的 ConfigMap 存在,
1194
+
但是在 ConfigMap 中没有名称为 `akey` 的键时,控制台输出也会为空。
1195
+
如果你确实在名为 `a-config` 的 ConfigMap 中为 `akey` 设置了键值,
1196
+
那么这个 Pod 会打印该值,然后终止。
1197
+
1198
+
<!--
1199
+
You can also mark the volumes and files provided by a ConfigMap as optional. Kubernetes always creates the mount paths for the volume, even if the referenced ConfigMap or key doesn't exist. For example, the following
1200
+
Pod specification marks a volume that references a ConfigMap as optional:
When a mounted ConfigMap is updated, the projected content is eventually updated too. This applies in the case where an optionally referenced ConfigMap comes into
1232
+
existence after a pod has started.
1233
+
-->
1234
+
当某个已被挂载的 ConfigMap 被更新,所投射的内容最终也会被更新。
1235
+
对于 Pod 已经启动之后所引用的、可选的 ConfigMap 才出现的情形,
1236
+
这一动态更新现象也是适用的。
1237
+
1238
+
<!--
1239
+
The kubelet checks whether the mounted ConfigMap is fresh on every periodic sync. However, it uses its local TTL-based cache for getting the current value of the
1240
+
ConfigMap. As a result, the total delay from the moment when the ConfigMap is updated to the moment when new keys are projected to the pod can be as long as
1241
+
kubelet sync period (1 minute by default) + TTL of ConfigMaps cache (1 minute by default) in kubelet.
1242
+
-->
1243
+
kubelet 在每次周期性同步时都会检查已挂载的 ConfigMap 是否是最新的。
1244
+
但是,它使用其本地的基于 TTL 的缓存来获取 ConfigMap 的当前值。
1245
+
因此,从更新 ConfigMap 到将新键映射到 Pod 的总延迟可能等于 kubelet 同步周期
0 commit comments