Skip to content

Commit 5dc911a

Browse files
authored
Merge pull request #36615 from yanrongshi/zh-cn]Sync-docs/tasks/inject-data-application/downward-api-volume-expose-pod-information.md
[zh-cn] Sync 2 files in tasks/inject-data-application/
2 parents 88380ad + 3daac90 commit 5dc911a

File tree

2 files changed

+82
-70
lines changed

2 files changed

+82
-70
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ A `downwardAPI` volume can expose Pod fields and container fields.
2020
<!--
2121
In Kubernetes, there are two ways to expose Pod and container fields to a running container:
2222
23-
* [Environment variables](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api)
23+
* [Environment variables](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/)
2424
* Volume files, as explained in this task
2525
2626
Together, these two ways of exposing Pod and container fields are called the
@@ -75,7 +75,7 @@ field should be stored in a file named `annotations`.
7575

7676
<!--
7777
The fields in this example are Pod fields. They are not
78-
fields of the Container in the Pod.
78+
fields of the container in the Pod.
7979
-->
8080
{{< note >}}
8181
本示例中的字段是 Pod 字段,不是 Pod 中容器的字段。

content/zh-cn/docs/tasks/inject-data-application/environment-variable-expose-pod-information.md

Lines changed: 80 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,63 @@ weight: 30
1212

1313
<!--
1414
This page shows how a Pod can use environment variables to expose information
15-
about itself to Containers running in the Pod. Environment variables can expose
16-
Pod fields and Container fields.
15+
about itself to containers running in the Pod, using the _downward API_.
16+
You can use environment variables to expose Pod fields, container fields, or both.
1717
-->
18-
此页面展示 Pod 如何使用环境变量把自己的信息呈现给 Pod 中运行的容器。
19-
环境变量可以呈现 Pod 的字段和容器字段
18+
此页面展示 Pod 如何使用环境变量把自身的信息呈现给 Pod 中运行的容器。
19+
使用 **downward API** 你可以使用环境变量来呈现 Pod 的字段、容器字段或两者
2020

21-
## {{% heading "prerequisites" %}}
21+
<!--
22+
In Kubernetes, there are two ways to expose Pod and container fields to a running container:
2223
23-
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
24+
* _Environment variables_, as explained in this task
25+
* [Volume files](/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/)
2426
25-
<!-- steps -->
27+
Together, these two ways of exposing Pod and container fields are called the
28+
downward API.
29+
-->
30+
在 Kubernetes 中有两种方式可以将 Pod 和 容器字段呈现给运行中的容器:
2631

27-
## Downward API
32+
* 如本任务所述的**环境变量**
33+
* [卷文件](/zh-cn/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/)
2834

29-
<!--
30-
There are two ways to expose Pod and Container fields to a running Container:
35+
这两种呈现 Pod 和 容器字段的方式统称为 downward API。
3136

32-
* Environment variables
33-
* [Volume Files](/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#the-downward-api)
3437

35-
Together, these two ways of exposing Pod and Container fields are called the
36-
*Downward API*.
37-
-->
38-
39-
有两种方式可以将 Pod 和 Container 字段呈现给运行中的容器:
38+
## {{% heading "prerequisites" %}}
4039

41-
* 环境变量
42-
* [卷文件](/zh-cn/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#the-downward-api)
40+
{{< include "task-tutorial-prereqs.md" >}}
4341

44-
这两种呈现 Pod 和 Container 字段的方式统称为 *Downward API*
42+
<!-- steps -->
4543

4644
<!--
4745
## Use Pod fields as values for environment variables
4846
49-
In this exercise, you create a Pod that has one Container. Here is the
50-
configuration file for the Pod:
47+
In this part of exercise, you create a Pod that has one container, and you
48+
project Pod-level fields into the running container as environment variables.
5149
-->
5250
## 用 Pod 字段作为环境变量的值
5351

54-
在这个练习中,你将创建一个包含一个容器的 Pod。这是该 Pod 的配置文件:
52+
在这部分练习中,你将创建一个包含一个容器的 Pod。并将 Pod 级别的字段作为环境变量映射到正在运行的容器中。
5553

5654
{{< codenew file="pods/inject/dapi-envars-pod.yaml" >}}
5755

5856
<!--
59-
In the configuration file, you can see five environment variables. The `env`
57+
In that manifest, you can see five environment variables. The `env`
6058
field is an array of
61-
[EnvVars](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvar-v1-core).
59+
environment variable definitions.
6260
The first element in the array specifies that the `MY_NODE_NAME` environment
6361
variable gets its value from the Pod's `spec.nodeName` field. Similarly, the
6462
other environment variables get their names from Pod fields.
6563
-->
66-
这个配置文件中,你可以看到五个环境变量。`env` 字段是一个
67-
[EnvVars](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvar-v1-core).
68-
对象的数组。
64+
这个清单中,你可以看到五个环境变量。`env` 字段定义了一组环境变量。
65+
6966
数组中第一个元素指定 `MY_NODE_NAME` 这个环境变量从 Pod 的 `spec.nodeName` 字段获取变量值。
7067
同样,其它环境变量也是从 Pod 的字段获取它们的变量值。
7168

7269
<!--
7370
The fields in this example are Pod fields. They are not fields of the
74-
Container in the Pod.
71+
container in the Pod.
7572
-->
7673
{{< note >}}
7774
本示例中的字段是 Pod 字段,不是 Pod 中 Container 的字段。
@@ -91,16 +88,17 @@ Verify that the Container in the Pod is running:
9188
-->
9289
验证 Pod 中的容器运行正常:
9390

94-
```
91+
```shell
92+
# 如果新创建的 Pod 还是处于不健康状态,请重新运行此命令几次。
9593
kubectl get pods
9694
```
9795

9896
<!--
99-
View the Container's logs:
97+
View the container's logs:
10098
-->
10199
查看容器日志:
102100

103-
```
101+
```shell
104102
kubectl logs dapi-envars-fieldref
105103
```
106104

@@ -119,17 +117,17 @@ default
119117

120118
<!--
121119
To see why these values are in the log, look at the `command` and `args` fields
122-
in the configuration file. When the Container starts, it writes the values of
120+
in the configuration file. When the container starts, it writes the values of
123121
five environment variables to stdout. It repeats this every ten seconds.
124122
125-
Next, get a shell into the Container that is running in your Pod:
123+
Next, get a shell into the container that is running in your Pod:
126124
-->
127-
要了解为什么这些值在日志中,请查看配置文件中的`command``args`字段。
128-
当容器启动时,它将五个环境变量的值写入 stdout。每十秒重复执行一次。
125+
要了解为什么这些值出现在日志中,请查看配置文件中的 `command``args` 字段。
126+
当容器启动时,它将五个环境变量的值写入标准输出。每十秒重复执行一次。
129127

130128
接下来,通过打开一个 Shell 进入 Pod 中运行的容器:
131129

132-
```
130+
```shell
133131
kubectl exec -it dapi-envars-fieldref -- sh
134132
```
135133

@@ -138,8 +136,9 @@ In your shell, view the environment variables:
138136
-->
139137
在 Shell 中,查看环境变量:
140138

141-
```
142-
/# printenv
139+
```shell
140+
# 在容器内的 `shell` 中运行
141+
printenv
143142
```
144143

145144
<!--
@@ -160,42 +159,41 @@ MY_POD_NAME=dapi-envars-fieldref
160159
```
161160

162161
<!--
163-
## Use Container fields as values for environment variables
162+
## Use container fields as values for environment variables
163+
164+
In the preceding exercise, you used information from Pod-level fields as the values
165+
for environment variables.
166+
In this next exercise, you are going to pass fields that are part of the Pod
167+
definition, but taken from the specific
168+
[container](/docs/reference/kubernetes-api/workload-resources/pod-v1/#Container)
169+
rather than from the Pod overall.
170+
171+
Here is a manifest for another Pod that again has just one container:
164172
165-
In the preceding exercise, you used Pod fields as the values for environment
166-
variables. In this next exercise, you use Container fields as the values for
167-
environment variables. Here is the configuration file for a Pod that has one
168-
container:
169173
-->
170-
## 用 Container 字段作为环境变量的值
174+
## 使用容器字段作为环境变量的值
175+
176+
前面的练习中,你将 Pod 级别的字段作为环境变量的值。
177+
接下来这个练习中,你将传递属于 Pod 定义的字段,但这些字段取自特定容器而不是整个 Pod。
171178

172-
前面的练习中,你将 Pod 字段作为环境变量的值。
173-
接下来这个练习中,你将用 Container 字段作为环境变量的值。这里是包含一个容器的 Pod 的配置文件:
179+
这里是只包含一个容器的 Pod 的清单:
174180

175181
{{< codenew file="pods/inject/dapi-envars-container.yaml" >}}
176182

177183
<!--
178-
In the configuration file, you can see four environment variables. The `env`
184+
In this manifest, you can see four environment variables. The `env`
179185
field is an array of
180-
[EnvVars](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvar-v1-core).
186+
environment variable definitions.
181187
The first element in the array specifies that the `MY_CPU_REQUEST` environment
182-
variable gets its value from the `requests.cpu` field of a Container named
188+
variable gets its value from the `requests.cpu` field of a container named
183189
`test-container`. Similarly, the other environment variables get their values
184-
from Container fields.
185-
186-
The fields in this example are Pod fields. They are not fields of the
187-
Container in the Pod.
190+
from fields that are specific to this container.
188191
189192
Create the Pod:
190193
-->
191-
这个配置文件中,你可以看到四个环境变量。`env` 字段是一个
192-
[EnvVars](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvar-v1-core).
193-
对象的数组。数组中第一个元素指定 `MY_CPU_REQUEST` 这个环境变量从 Container 的 `requests.cpu`
194-
字段获取变量值。同样,其它环境变量也是从 Container 的字段获取它们的变量值。
195-
196-
{{< note >}}
197-
本例中使用的是 Container 的字段而不是 Pod 的字段。
198-
{{< /note >}}
194+
这个清单中,你可以看到四个环境变量。`env` 字段定义了一组环境变量。
195+
数组中第一个元素指定 `MY_CPU_REQUEST` 这个环境变量从容器的 `requests.cpu`
196+
字段获取变量值。同样,其它的环境变量也是从特定于这个容器的字段中获取它们的变量值。
199197

200198
创建Pod:
201199

@@ -204,20 +202,21 @@ kubectl apply -f https://k8s.io/examples/pods/inject/dapi-envars-container.yaml
204202
```
205203

206204
<!--
207-
Verify that the Container in the Pod is running:
205+
Verify that the container in the Pod is running:
208206
-->
209207
验证 Pod 中的容器运行正常:
210208

211-
```
209+
```shell
210+
# 如果新创建的 Pod 还是处于不健康状态,请重新运行此命令几次。
212211
kubectl get pods
213212
```
214213

215214
<!--
216-
View the Container's logs:
215+
View the container's logs:
217216
-->
218217
查看容器日志:
219218

220-
```
219+
```shell
221220
kubectl logs dapi-envars-resourcefieldref
222221
```
223222

@@ -236,16 +235,29 @@ The output shows the values of selected environment variables:
236235
## {{% heading "whatsnext" %}}
237236

238237
<!--
239-
* [Defining Environment Variables for a Container](/docs/tasks/inject-data-application/define-environment-variable-container/)
238+
* Read [Defining Environment Variables for a Container](/docs/tasks/inject-data-application/define-environment-variable-container/)
239+
* Read the [`spec`](/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodSpec)
240+
API definition for Pod. This includes the definition of Container (part of Pod).
241+
* Read the list of [available fields](/docs/concepts/workloads/pods/downward-api/#available-fields) that you
242+
can expose using the downward API.
243+
-->
244+
* 阅读[给容器定义环境变量](/zh-cn/docs/tasks/inject-data-application/define-environment-variable-container/)
245+
* 阅读 Pod 的 [`spec`](/zh-cn/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodSpec)
246+
API 包括容器(Pod 的一部分)的定义。
247+
* 阅读可以使用 downward API 公开的[可用字段](/zh-cn/docs/concepts/workloads/pods/downward-api/#available-fields)列表。
248+
249+
<!--
250+
Read about Pods, containers and environment variables in the legacy API reference:
251+
240252
* [PodSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
241253
* [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)
242254
* [EnvVar](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvar-v1-core)
243255
* [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core)
244256
* [ObjectFieldSelector](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#objectfieldselector-v1-core)
245257
* [ResourceFieldSelector](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcefieldselector-v1-core)
246258
-->
259+
在旧版 API 参考中阅读有关 Pod、容器和环境变量的信息:
247260

248-
* [给容器定义环境变量](/zh-cn/docs/tasks/inject-data-application/define-environment-variable-container/)
249261
* [PodSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
250262
* [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)
251263
* [EnvVar](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvar-v1-core)

0 commit comments

Comments
 (0)