Skip to content

Commit 48edf9e

Browse files
authored
Merge pull request #33914 from fenggw-fnst/tasks-13
[zh] Sync kubelet-credential-provider.md and downward-api-volume-expose-pod-information.md
2 parents ca2b940 + adbf29f commit 48edf9e

File tree

2 files changed

+155
-74
lines changed

2 files changed

+155
-74
lines changed

content/zh/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information.md

Lines changed: 114 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ weight: 40
77
<!-- overview -->
88

99
<!--
10-
This page shows how a Pod can use a DownwardAPIVolumeFile to expose information
11-
about itself to Containers running in the Pod. A DownwardAPIVolumeFile can expose
12-
Pod fields and Container fields.
10+
This page shows how a Pod can use a
11+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
12+
to expose information about itself to Containers running in the Pod.
13+
A `DownwardAPIVolumeFile` can expose Pod fields and Container fields.
1314
-->
14-
此页面描述 Pod 如何使用 DownwardAPIVolumeFile 把自己的信息呈现给 Pod 中运行的容器。
15-
DownwardAPIVolumeFile 可以呈现 Pod 的字段和容器字段。
15+
此页面描述 Pod 如何使用
16+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
17+
把自己的信息呈现给 Pod 中运行的容器。
18+
`DownwardAPIVolumeFile` 可以呈现 Pod 和容器的字段。
1619

1720
## {{% heading "prerequisites" %}}
1821

@@ -26,24 +29,27 @@ DownwardAPIVolumeFile 可以呈现 Pod 的字段和容器字段。
2629
There are two ways to expose Pod and Container fields to a running Container:
2730
2831
* [Environment variables](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api)
29-
* Volume Files
32+
* Volume files
33+
34+
Together, these two ways of exposing Pod and Container fields are called the
35+
"Downward API".
3036
-->
31-
## Downward API
37+
## Downward API {#the-downward-api}
3238

3339
有两种方式可以将 Pod 和 Container 字段呈现给运行中的容器:
3440

3541
* [环境变量](/zh/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api)
3642
* 卷文件
3743

38-
这两种呈现 Pod 和 Container 字段的方式都称为 *Downward API*
44+
这两种呈现 Pod 和 Container 字段的方式都称为 "Downward API"
3945

4046
<!--
4147
## Store Pod fields
4248
4349
In this exercise, you create a Pod that has one Container.
4450
Here is the configuration file for the Pod:
4551
-->
46-
## 存储 Pod 字段
52+
## 存储 Pod 字段 {#store-pod-fields}
4753

4854
在这个练习中,你将创建一个包含一个容器的 Pod。Pod 的配置文件如下:
4955

@@ -88,7 +94,7 @@ kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume.yaml
8894
```
8995

9096
<!--
91-
Verify that the Container in the Pod is running:
97+
Verify that the container in the Pod is running:
9298
-->
9399
验证Pod中的容器运行正常:
94100

@@ -97,7 +103,7 @@ kubectl get pods
97103
```
98104

99105
<!--
100-
View the Container's logs:
106+
View the container's logs:
101107
-->
102108
查看容器的日志:
103109

@@ -120,7 +126,7 @@ builder="john-doe"
120126
```
121127

122128
<!--
123-
Get a shell into the Container that is running in your Pod:
129+
Get a shell into the container that is running in your Pod:
124130
-->
125131
进入 Pod 中运行的容器,打开一个 Shell:
126132

@@ -194,11 +200,10 @@ total 8
194200
<!--
195201
Using symbolic links enables dynamic atomic refresh of the metadata; updates are
196202
written to a new temporary directory, and the `..data` symlink is updated
197-
atomically using
198-
[rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html).
203+
atomically using [rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html).
199204
-->
200205
用符号链接可实现元数据的动态原子性刷新;更新将写入一个新的临时目录,
201-
然后通过使用[rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html)
206+
然后通过使用 [rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html)
202207
完成 `..data` 符号链接的原子性更新。
203208

204209
<!--
@@ -218,24 +223,30 @@ Downward API,则该容器无法收到更新事件。
218223
/# exit
219224
```
220225

221-
## 存储容器字段
222-
223226
<!--
224-
The preceding exercise, you stored Pod fields in a DownwardAPIVolumeFile.
227+
## Store Container fields
228+
229+
The preceding exercise, you stored Pod fields in a
230+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)..
225231
In this next exercise, you store Container fields. Here is the configuration
226232
file for a Pod that has one Container:
227233
-->
228-
前面的练习中,你将 Pod 字段保存到 DownwardAPIVolumeFile 中。
234+
## 存储容器字段 {#store-container-fields}
235+
236+
前面的练习中,你将 Pod 字段保存到
237+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
238+
中。
229239
接下来这个练习,你将存储 Container 字段。这里是包含一个容器的 Pod 的配置文件:
230240

231241
{{< codenew file="pods/inject/dapi-volume-resources.yaml" >}}
232242

233243
<!--
234-
In the configuration file, you can see that the Pod has a `downwardAPI` Volume,
235-
and the Container mounts the Volume at `/etc/podinfo`.
244+
In the configuration file, you can see that the Pod has a
245+
[`downwardAPI` volume](/concepts/storage/volumes/#downwardapi),
246+
and the Container mounts the volume at `/etc/podinfo`.
236247
237248
Look at the `items` array under `downwardAPI`. Each element of the array is a
238-
DownwardAPIVolumeFile.
249+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core).
239250
240251
The first element specifies that in the Container named `client-container`,
241252
the value of the `limits.cpu` field in the format specified by `1m` should be
@@ -244,13 +255,16 @@ default value of `1` which means cores for cpu and bytes for memory.
244255
245256
Create the Pod:
246257
-->
247-
在这个配置文件中,你可以看到 Pod 有一个 `downwardAPI` 类型的卷,并且挂载到容器的
248-
`/etc/podinfo` 目录。
258+
在这个配置文件中,你可以看到 Pod 有一个
259+
[`downwardAPI`](/zh/docs/concepts/storage/volumes/#downwardapi)
260+
并且挂载到容器的 `/etc/podinfo` 目录。
249261

250-
查看 `downwardAPI` 下面的 `items` 数组。每个数组元素都是一个 DownwardAPIVolumeFile。
262+
查看 `downwardAPI` 下面的 `items` 数组。每个数组元素都是一个
263+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)。
251264

252-
第一个元素指定名为 `client-container` 的容器中 `limits.cpu` 字段的值应保存在名为
253-
`cpu_limit` 的文件中。
265+
第一个元素指定在名为 `client-container` 的容器中,
266+
`1m` 所指定格式的 `limits.cpu` 字段的值应保存在名为 `cpu_limit` 的文件中。
267+
`divisor` 字段是可选的,默认值为 `1`,表示 CPU 的核心和内存的字节。
254268

255269
创建Pod:
256270

@@ -259,7 +273,7 @@ kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume-resources.yaml
259273
```
260274

261275
<!--
262-
Get a shell into the Container that is running in your Pod:
276+
Get a shell into the container that is running in your Pod:
263277
-->
264278
打开一个 Shell,进入 Pod 中运行的容器:
265279

@@ -283,39 +297,50 @@ You can use similar commands to view the `cpu_request`, `mem_limit` and
283297
你可以使用同样的命令查看 `cpu_request``mem_limit``mem_request` 文件.
284298

285299
<!-- discussion -->
300+
301+
<!-- TODO: This section should be extracted out of the task page. -->
286302
<!--
287303
## Capabilities of the Downward API
288304
-->
289-
## Downward API 的能力
305+
## Downward API 的能力 {#capabilities-of-the-downward-api}
290306

291307
<!--
292308
The following information is available to containers through environment
293309
variables and `downwardAPI` volumes:
294310
295311
* Information available via `fieldRef`:
312+
296313
* `metadata.name` - the pod's name
297314
* `metadata.namespace` - the pod's namespace
298315
* `metadata.uid` - the pod's UID
299-
* `metadata.labels['<KEY>']` - the value of the pod's label `<KEY>` (for example, `metadata.labels['mylabel']`)
300-
* `metadata.annotations['<KEY>']` - the value of the pod's annotation `<KEY>` (for example, `metadata.annotations['myannotation']`)
316+
* `metadata.labels['<KEY>']` - the value of the pod's label `<KEY>`
317+
(for example, `metadata.labels['mylabel']`)
318+
* `metadata.annotations['<KEY>']` - the value of the pod's annotation `<KEY>`
319+
(for example, `metadata.annotations['myannotation']`)
301320
-->
302321
下面这些信息可以通过环境变量和 `downwardAPI` 卷提供给容器:
303322

304323
* 能通过 `fieldRef` 获得的:
324+
305325
* `metadata.name` - Pod 名称
306326
* `metadata.namespace` - Pod 名字空间
307327
* `metadata.uid` - Pod 的 UID
308-
* `metadata.labels['<KEY>']` - Pod 标签 `<KEY>` 的值 (例如, `metadata.labels['mylabel']`
309-
* `metadata.annotations['<KEY>']` - Pod 的注解 `<KEY>` 的值(例如, `metadata.annotations['myannotation']`
328+
* `metadata.labels['<KEY>']` - Pod 标签 `<KEY>` 的值
329+
(例如:`metadata.labels['mylabel']`
330+
* `metadata.annotations['<KEY>']` - Pod 的注解 `<KEY>` 的值
331+
(例如:`metadata.annotations['myannotation']`
310332

311333
<!--
312334
* Information available via `resourceFieldRef`:
335+
313336
* A Container's CPU limit
314337
* A Container's CPU request
315338
* A Container's memory limit
316339
* A Container's memory request
317-
* A Container's hugepages limit (providing that the `DownwardAPIHugePages` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
318-
* A Container's hugepages request (providing that the `DownwardAPIHugePages` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
340+
* A Container's hugepages limit (provided that the `DownwardAPIHugePages`
341+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
342+
* A Container's hugepages request (provided that the `DownwardAPIHugePages`
343+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
319344
* A Container's ephemeral-storage limit
320345
* A Container's ephemeral-storage request
321346
-->
@@ -324,8 +349,10 @@ variables and `downwardAPI` volumes:
324349
* 容器的 CPU 请求值
325350
* 容器的内存约束值
326351
* 容器的内存请求值
327-
* 容器的巨页限制值(前提是启用了 `DownwardAPIHugePages` [特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
328-
* 容器的巨页请求值(前提是启用了 `DownwardAPIHugePages` [特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
352+
* 容器的巨页限制值(前提是启用了 `DownwardAPIHugePages`
353+
[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
354+
* 容器的巨页请求值(前提是启用了 `DownwardAPIHugePages`
355+
[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
329356
* 容器的临时存储约束值
330357
* 容器的临时存储请求值
331358

@@ -334,23 +361,33 @@ In addition, the following information is available through
334361
`downwardAPI` volume `fieldRef`:
335362
-->
336363
此外,以下信息可通过 `downwardAPI` 卷从 `fieldRef` 获得:
364+
337365
<!--
338-
* `metadata.labels` - all of the pod’s labels, formatted as `label-key="escaped-label-value"` with one label per line
339-
* `metadata.annotations` - all of the pod’s annotations, formatted as `annotation-key="escaped-annotation-value"` with one annotation per line
366+
* `metadata.labels` - all of the pod's labels, formatted as `label-key="escaped-label-value"`
367+
with one label per line
368+
* `metadata.annotations` - all of the pod's annotations, formatted as
369+
`annotation-key="escaped-annotation-value"` with one annotation per line
340370
-->
341-
* `metadata.labels` - Pod 的所有标签,以 `label-key="escaped-label-value"` 格式显示,每行显示一个标签
342-
* `metadata.annotations` - Pod 的所有注解,以 `annotation-key="escaped-annotation-value"`
343-
格式显示,每行显示一个标签
371+
* `metadata.labels` - Pod 的所有标签,以
372+
`label-key="escaped-label-value"` 格式显示,每行显示一个标签
373+
* `metadata.annotations` - Pod 的所有注解,以
374+
`annotation-key="escaped-annotation-value"` 格式显示,每行显示一个标签
344375

345376
<!--
346377
The following information is available through environment variables:
378+
379+
* `status.podIP` - the pod's IP address
380+
* `spec.serviceAccountName` - the pod's service account name
381+
* `spec.nodeName` - the name of the node to which the scheduler always attempts to
382+
schedule the pod
383+
* `status.hostIP` - the IP of the node to which the Pod is assigned
347384
-->
348385
以下信息可通过环境变量获得:
349386

350-
* `status.podIP` - 节点 IP
351-
* `spec.serviceAccountName` - Pod 服务帐号名称, 版本要求 v1.4.0-alpha.3
352-
* `spec.nodeName` - 节点名称, 版本要求 v1.4.0-alpha.3
353-
* `status.hostIP` - 节点 IP, 版本要求 v1.7.0-alpha.1
387+
* `status.podIP` - Pod IP 地址
388+
* `spec.serviceAccountName` - Pod 服务帐号名称
389+
* `spec.nodeName` - 调度器总是尝试将 Pod 调度到的节点的名称
390+
* `status.hostIP` - Pod 分配到的节点的 IP
354391

355392
<!--
356393
If CPU and memory limits are not specified for a Container, the
@@ -368,15 +405,15 @@ You can project keys to specific paths and specific permissions on a per-file
368405
basis. For more information, see
369406
[Secrets](/docs/concepts/configuration/secret/).
370407
-->
371-
## 投射键名到指定路径并且指定文件权限
408+
## 投射键名到指定路径并且指定文件权限 {#project-keys-to-specific-paths-and-file-permissions}
372409

373410
你可以将键名投射到指定路径并且指定每个文件的访问权限。
374411
更多信息,请参阅[Secrets](/zh/docs/concepts/configuration/secret/).
375412

376413
<!--
377414
## Motivation for the Downward API
378415
379-
It is sometimes useful for a Container to have information about itself, without
416+
It is sometimes useful for a container to have information about itself, without
380417
being overly coupled to Kubernetes. The Downward API allows containers to consume
381418
information about themselves or the cluster without using the Kubernetes client
382419
or API server.
@@ -387,7 +424,7 @@ application, but that is tedious and error prone, and it violates the goal of lo
387424
coupling. A better option would be to use the Pod's name as an identifier, and
388425
inject the Pod's name into the well-known environment variable.
389426
-->
390-
## Downward API的动机
427+
## Downward API 的动机 {#motivation-for-the-downward-api}
391428

392429
对于容器来说,有时候拥有自己的信息是很有用的,可避免与 Kubernetes 过度耦合。
393430
Downward API 使得容器使用自己或者集群的信息,而不必通过 Kubernetes 客户端或
@@ -399,9 +436,32 @@ API 服务器来获得。
399436

400437
## {{% heading "whatsnext" %}}
401438

402-
* [PodSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
403-
* [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
404-
* [DownwardAPIVolumeSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumesource-v1-core)
405-
* [DownwardAPIVolumeFile](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
406-
* [ResourceFieldSelector](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcefieldselector-v1-core)
439+
<!--
440+
* Check the [`PodSpec`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
441+
API definition which defines the desired state of a Pod.
442+
* Check the [`Volume`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
443+
API definition which defines a generic volume in a Pod for containers to access.
444+
* Check the [`DownwardAPIVolumeSource`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumesource-v1-core)
445+
API definition which defines a volume that contains Downward API information.
446+
* Check the [`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
447+
API definition which contains references to object or resource fields for
448+
populating a file in the Downward API volume.
449+
* Check the [`ResourceFieldSelector`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcefieldselector-v1-core)
450+
API definition which specifies the container resources and their output format.
451+
-->
452+
* 参阅
453+
[`PodSpec`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
454+
API 定义,该 API 定义 Pod 所需状态。
455+
* 参阅
456+
[`Volume`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
457+
API 定义,该 API 在 Pod 中定义通用卷以供容器访问。
458+
* 参阅
459+
[`DownwardAPIVolumeSource`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumesource-v1-core)
460+
API 定义,该 API 定义包含 Downward API 信息的卷。
461+
* 参阅
462+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
463+
API 定义,该 API 包含对对象或资源字段的引用,用于在 Downward API 卷中填充文件。
464+
* 参阅
465+
[`ResourceFieldSelector`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcefieldselector-v1-core)
466+
API 定义,该 API 指定容器资源及其输出格式。
407467

0 commit comments

Comments
 (0)