@@ -83,7 +83,7 @@ username and password:
8383 Output:
8484 -->
8585 输出:
86-
86+
8787 ```
8888 NAME TYPE DATA AGE
8989 test-secret Opaque 2 1m
@@ -222,59 +222,204 @@ Here is a configuration file you can use to create a Pod:
222222 my-app
223223 39528$vdg7Jb
224224 ```
225+ <!--
226+ Modify your image or command line so that the program looks for files in the
227+ `mountPath` directory. Each key in the Secret `data` map becomes a file name
228+ in this directory.
229+ -->
230+ 修改你的镜像或命令行,使程序在 ` mountPath ` 目录下查找文件。
231+ Secret ` data ` 映射中的每个键都成为该目录中的文件名。
225232
226233<!--
227- ## Define container environment variables using Secret data
234+ ### Project Secret keys to specific file paths
228235
229- ### Define a container environment variable with data from a single Secret
236+ You can also control the paths within the volume where Secret keys are projected. Use the `.spec.volumes[].secret.items` field to change the target
237+ path of each key:
238+ -->
239+ ### 映射 Secret 键到特定文件路径 {#project-secret-keys-to-specific-file-paths}
240+
241+ 你还可以控制卷内 Secret 键的映射路径。
242+ 使用 ` .spec.volumes[].secret.items ` 字段来改变每个键的目标路径。
243+
244+ ``` yaml
245+ apiVersion : v1
246+ kind : Pod
247+ metadata :
248+ name : mypod
249+ spec :
250+ containers :
251+ - name : mypod
252+ image : redis
253+ volumeMounts :
254+ - name : foo
255+ mountPath : " /etc/foo"
256+ readOnly : true
257+ volumes :
258+ - name : foo
259+ secret :
260+ secretName : mysecret
261+ items :
262+ - key : username
263+ path : my-group/my-username
264+ ` ` `
265+
266+ <!--
267+ When you deploy this Pod, the following happens:
268+ -->
269+ 当你部署此 Pod 时,会发生以下情况:
270+
271+ <!--
272+ * The ` username` key from `mysecret` is available to the container at the path
273+ ` /etc/foo/my-group/my-username` instead of at `/etc/foo/username`.
274+ * The `password` key from that Secret object is not projected.
275+ -->
276+ * 来自 `mysecret` 的键 `username` 可以在路径 `/etc/foo/my-group/my-username`
277+ 下供容器使用,而不是路径 `/etc/foo/username`。
278+ * 来自该 Secret 的键 `password` 没有映射到任何路径。
279+
280+ <!--
281+ If you list keys explicitly using `.spec.volumes[].secret.items`, consider the
282+ following :
283+ -->
284+
285+ 如果你使用 `.spec.volumes[].secret.items` 明确地列出键,请考虑以下事项:
286+
287+ <!--
288+ * Only keys specified in `items` are projected.
289+ * To consume all keys from the Secret, all of them must be listed in the
290+ ` items` field.
291+ * All listed keys must exist in the corresponding Secret. Otherwise, the volume
292+ is not created.
293+ -->
294+ * 只有在 `items` 字段中指定的键才会被映射。
295+ * 要使用 Secret 中全部的键,那么全部的键都必须列在 `items` 字段中。
296+ * 所有列出的键必须存在于相应的 Secret 中。否则,该卷不被创建。
297+
298+ <!--
299+ # ## Set POSIX permissions for Secret keys
300+
301+ You can set the POSIX file access permission bits for a single Secret key.
302+ If you don't specify any permissions, `0644` is used by default.
303+ You can also set a default POSIX file mode for the entire Secret volume, and
304+ you can override per key if needed.
305+ -->
306+ # ## 为 Secret 键设置 POSIX 权限
307+
308+ 你可以为单个 Secret 键设置 POSIX 文件访问权限位。
309+ 如果不指定任何权限,默认情况下使用 `0644`。
310+ 你也可以为整个 Secret 卷设置默认的 POSIX 文件模式,需要时你可以重写单个键的权限。
230311
312+ <!--
313+ For example, you can specify a default mode like this :
314+ -->
315+ 例如,可以像这样指定默认模式:
316+
317+ ` ` ` yaml
318+ apiVersion: v1
319+ kind: Pod
320+ metadata:
321+ name: mypod
322+ spec:
323+ containers:
324+ - name: mypod
325+ image: redis
326+ volumeMounts:
327+ - name: foo
328+ mountPath: "/etc/foo"
329+ volumes:
330+ - name: foo
331+ secret:
332+ secretName: mysecret
333+ defaultMode: 0400
334+ ` ` `
335+
336+ <!--
337+ The Secret is mounted on `/etc/foo`; all the files created by the
338+ secret volume mount have permission `0400`.
339+ -->
340+ Secret 被挂载在 `/etc/foo` 目录下;所有由 Secret 卷挂载创建的文件的访问许可都是 `0400`。
341+
342+ {{< note >}}
343+ <!--
344+ If you're defining a Pod or a Pod template using JSON, beware that the JSON
345+ specification doesn't support octal literals for numbers because JSON considers
346+ ` 0400` to be the _decimal_ value `400`. In JSON, use decimal values for the
347+ ` defaultMode` instead. If you're writing YAML, you can write the `defaultMode`
348+ in octal.
349+ -->
350+ 如果使用 JSON 定义 Pod 或 Pod 模板,请注意 JSON 规范不支持数字的八进制形式,
351+ 因为 JSON 将 `0400` 视为**十进制**的值 `400`。
352+ 在 JSON 中,要改为使用十进制的 `defaultMode`。
353+ 如果你正在编写 YAML,则可以用八进制编写 `defaultMode`。
354+ {{< /note >}}
355+
356+ <!--
357+ # # Define container environment variables using Secret data
231358-->
232359# # 使用 Secret 数据定义容器变量 {#define-container-env-var-using-secret-data}
233360
361+ <!--
362+ You can consume the data in Secrets as environment variables in your
363+ containers.
364+
365+ If a container already consumes a Secret in an environment variable,
366+ a Secret update will not be seen by the container unless it is
367+ restarted. There are third party solutions for triggering restarts when
368+ secrets change.
369+ -->
370+ 在你的容器中,你可以以环境变量的方式使用 Secret 中的数据。
371+
372+ 如果容器已经使用了在环境变量中的 Secret,除非容器重新启动,否则容器将无法感知到 Secret 的更新。
373+ 有第三方解决方案可以在 Secret 改变时触发容器重启。
374+
375+ <!--
376+ # ## Define a container environment variable with data from a single Secret
377+ -->
378+
234379# ## 使用来自 Secret 中的数据定义容器变量 {#define-a-container-env-var-with-data-from-a-single-secret}
235380
236381<!--
237- * Define an environment variable as a key-value pair in a Secret:
382+ * Define an environment variable as a key-value pair in a Secret:
238383-->
239- * 定义环境变量为 Secret 中的键值偶对:
384+ * 定义环境变量为 Secret 中的键值偶对:
240385
241- ``` shell
242- kubectl create secret generic backend-user --from-literal=backend-username=' backend-admin'
243- ```
386+ ` ` ` shell
387+ kubectl create secret generic backend-user --from-literal=backend-username='backend-admin'
388+ ` ` `
244389
245390<!--
246391* Assign the `backend-username` value defined in the Secret to the `SECRET_USERNAME` environment variable in the Pod specification.
247392-->
248- * 在 Pod 规约中,将 Secret 中定义的值 ` backend-username ` 赋给 ` SECRET_USERNAME ` 环境变量。
393+ * 在 Pod 规约中,将 Secret 中定义的值 `backend-username` 赋给 `SECRET_USERNAME` 环境变量。
249394
250- {{< codenew file="pods/inject/pod-single-secret-env-variable.yaml" >}}
395+ {{< codenew file="pods/inject/pod-single-secret-env-variable.yaml" >}}
251396
252397<!--
253398* Create the Pod:
254399-->
255- * 创建 Pod:
400+ * 创建 Pod:
256401
257- ``` shell
258- kubectl create -f https://k8s.io/examples/pods/inject/pod-single-secret-env-variable.yaml
259- ```
402+ ` ` ` shell
403+ kubectl create -f https://k8s.io/examples/pods/inject/pod-single-secret-env-variable.yaml
404+ ` ` `
260405
261406<!--
262407* In your shell, display the content of `SECRET_USERNAME` container environment variable
263408-->
264- * 在 Shell 中,显示容器环境变量 ` SECRET_USERNAME ` 的内容:
409+ * 在 Shell 中,显示容器环境变量 `SECRET_USERNAME` 的内容:
265410
266- ``` shell
267- kubectl exec -i -t env-single-secret -- /bin/sh -c ' echo $SECRET_USERNAME'
411+ ` ` ` shell
412+ kubectl exec -i -t env-single-secret -- /bin/sh -c 'echo $SECRET_USERNAME'
268413 ` ` `
269414
270- <!--
271- The output is
272- -->
273- 输出为:
274- ```
275- backend-admin
276- ```
277-
415+ <!--
416+ The output is
417+ -->
418+ 输出为:
419+ ```
420+ backend-admin
421+ ```
422+
278423<!--
279424### Define container environment variables with data from multiple Secrets
280425-->
@@ -283,45 +428,45 @@ Here is a configuration file you can use to create a Pod:
283428<!--
284429* As with the previous example, create the Secrets first.
285430-->
286- * 和前面的例子一样,先创建 Secret:
431+ * 和前面的例子一样,先创建 Secret:
287432
288- ``` shell
289- kubectl create secret generic backend-user --from-literal=backend-username=' backend-admin'
290- kubectl create secret generic db-user --from-literal=db-username=' db-admin'
291- ```
433+ ```shell
434+ kubectl create secret generic backend-user --from-literal=backend-username='backend-admin'
435+ kubectl create secret generic db-user --from-literal=db-username='db-admin'
436+ ```
292437
293438<!--
294439* Define the environment variables in the Pod specification.
295440-->
296- * 在 Pod 规约中定义环境变量:
441+ * 在 Pod 规约中定义环境变量:
297442
298- {{< codenew file="pods/inject/pod-multiple-secret-env-variable.yaml" >}}
443+ {{< codenew file="pods/inject/pod-multiple-secret-env-variable.yaml" >}}
299444
300445<!--
301446* Create the Pod:
302447-->
303- * 创建 Pod:
448+ * 创建 Pod:
304449
305- ``` shell
306- kubectl create -f https://k8s.io/examples/pods/inject/pod-multiple-secret-env-variable.yaml
307- ```
450+ ``` shell
451+ kubectl create -f https://k8s.io/examples/pods/inject/pod-multiple-secret-env-variable.yaml
452+ ```
308453
309454<!--
310455* In your shell, display the container environment variables
311456-->
312- * 在你的 Shell 中,显示容器环境变量的内容:
457+ * 在你的 Shell 中,显示容器环境变量的内容:
313458
314- ``` shell
315- kubectl exec -i -t envvars-multiple-secrets -- /bin/sh -c ' env | grep _USERNAME'
316- ```
317- <!--
318- The output is
319- -->
320- 输出:
321- ```
322- DB_USERNAME=db-admin
323- BACKEND_USERNAME=backend-admin
324- ```
459+ ``` shell
460+ kubectl exec -i -t envvars-multiple-secrets -- /bin/sh -c ' env | grep _USERNAME'
461+ ```
462+ <!--
463+ The output is
464+ -->
465+ 输出:
466+ ```
467+ DB_USERNAME=db-admin
468+ BACKEND_USERNAME=backend-admin
469+ ```
325470
326471<!--
327472## Configure all key-value pairs in a Secret as container environment variables
@@ -338,28 +483,28 @@ This functionality is available in Kubernetes v1.6 and later.
338483<!--
339484* Create a Secret containing multiple key-value pairs
340485-->
341- * 创建包含多个键值偶对的 Secret:
486+ * 创建包含多个键值偶对的 Secret:
342487
343- ``` shell
344- kubectl create secret generic test-secret --from-literal=username=' my-app' --from-literal=password=' 39528$vdg7Jb'
345- ```
488+ ``` shell
489+ kubectl create secret generic test-secret --from-literal=username=' my-app' --from-literal=password=' 39528$vdg7Jb'
490+ ```
346491
347492<!--
348493* Use envFrom to define all of the Secret's data as container environment variables. The key from the Secret becomes the environment variable name in the Pod.
349494-->
350- * 使用 ` envFrom ` 来将 Secret 中的所有数据定义为环境变量。
351- Secret 中的键名成为容器中的环境变量名:
495+ * 使用 ` envFrom ` 来将 Secret 中的所有数据定义为环境变量。
496+ Secret 中的键名成为容器中的环境变量名:
352497
353- {{< codenew file="pods/inject/pod-secret-envFrom.yaml" >}}
498+ {{< codenew file="pods/inject/pod-secret-envFrom.yaml" >}}
354499
355500<!--
356501* Create the Pod:
357502-->
358- * 创建 Pod:
503+ * 创建 Pod:
359504
360- ``` shell
361- kubectl create -f https://k8s.io/examples/pods/inject/pod-secret-envFrom.yaml
362- ```
505+ ``` shell
506+ kubectl create -f https://k8s.io/examples/pods/inject/pod-secret-envFrom.yaml
507+ ```
363508
364509<!--
365510* In your shell, display `username` and `password` container environment variables
@@ -397,4 +542,3 @@ This functionality is available in Kubernetes v1.6 and later.
397542-->
398543* 进一步了解 [ Secret] ( /zh-cn/docs/concepts/configuration/secret/ ) 。
399544* 了解[ 卷] ( /zh-cn/docs/concepts/storage/volumes/ ) 。
400-
0 commit comments