@@ -3,6 +3,11 @@ title: 通过文件将 Pod 信息呈现给容器
3
3
content_type : task
4
4
weight : 40
5
5
---
6
+ <!--
7
+ title: Expose Pod Information to Containers Through Files
8
+ content_type: task
9
+ weight: 40
10
+ -->
6
11
7
12
<!-- overview -->
8
13
@@ -15,7 +20,7 @@ A `downwardAPI` volume can expose Pod fields and container fields.
15
20
此页面描述 Pod 如何使用
16
21
[ ` downwardAPI ` 卷] ( /zh-cn/docs/concepts/storage/volumes/#downwardapi )
17
22
把自己的信息呈现给 Pod 中运行的容器。
18
- ` downwardAPI ` 可以呈现 Pod 和容器的字段。
23
+ ` downwardAPI ` 卷可以呈现 Pod 和容器的字段。
19
24
20
25
<!--
21
26
In Kubernetes, there are two ways to expose Pod and container fields to a running container:
@@ -37,7 +42,6 @@ _downward API_.
37
42
38
43
{{< include "task-tutorial-prereqs.md" >}}
39
44
40
-
41
45
<!-- steps -->
42
46
43
47
<!--
@@ -49,7 +53,7 @@ Here is the manifest for the Pod:
49
53
-->
50
54
## 存储 Pod 字段 {#store-pod-fields}
51
55
52
- 在这部分的练习中,你将创建一个包含一个容器的 Pod,并将 Pod 级别的字段作为文件映射到正在运行的容器中 。
56
+ 在这部分的练习中,你将创建一个包含一个容器的 Pod,并将 Pod 级别的字段作为文件投射到正在运行的容器中 。
53
57
Pod 的清单如下:
54
58
55
59
{{< codenew file="pods/inject/dapi-volume.yaml" >}}
@@ -73,11 +77,11 @@ field should be stored in a file named `annotations`.
73
77
第一个元素指示 Pod 的 ` metadata.labels ` 字段的值保存在名为 ` labels ` 的文件中。
74
78
第二个元素指示 Pod 的 ` annotations ` 字段的值保存在名为 ` annotations ` 的文件中。
75
79
80
+ {{< note >}}
76
81
<!--
77
82
The fields in this example are Pod fields. They are not
78
83
fields of the container in the Pod.
79
84
-->
80
- {{< note >}}
81
85
本示例中的字段是 Pod 字段,不是 Pod 中容器的字段。
82
86
{{< /note >}}
83
87
@@ -93,7 +97,7 @@ kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume.yaml
93
97
<!--
94
98
Verify that the container in the Pod is running:
95
99
-->
96
- 验证Pod中的容器运行正常 :
100
+ 验证 Pod 中的容器运行正常 :
97
101
98
102
``` shell
99
103
kubectl get pods
@@ -111,7 +115,7 @@ kubectl logs kubernetes-downwardapi-volume-example
111
115
<!--
112
116
The output shows the contents of the `labels` file and the `annotations` file:
113
117
-->
114
- 输出显示 ` labels ` 和 ` annotations ` 文件的内容:
118
+ 输出显示 ` labels ` 文件和 ` annotations ` 文件的内容:
115
119
116
120
```
117
121
cluster="test-cluster1"
@@ -178,9 +182,9 @@ a symbolic link to the temporary subdirectory. Also in the `/etc/podinfo` direct
178
182
`labels` and `annotations` are symbolic links.
179
183
-->
180
184
在输出中可以看到,` labels ` 和 ` annotations ` 文件都在一个临时子目录中。
181
- 在这个例子, ` ..2982_06_02_21_47_53.299460680 ` 。
182
- 在 ` /etc/podinfo ` 目录中,` ..data ` 是一个指向临时子目录
183
- 的符号链接。 ` /etc/podinfo ` 目录中,` labels ` 和 ` annotations ` 也是符号链接。
185
+ 在这个例子中,这个临时子目录为 ` ..2982_06_02_21_47_53.299460680 ` 。
186
+ 在 ` /etc/podinfo ` 目录中,` ..data ` 是指向该临时子目录的符号链接。
187
+ 另外在 ` /etc/podinfo ` 目录中,` labels ` 和 ` annotations ` 也是符号链接。
184
188
185
189
```
186
190
drwxr-xr-x ... Feb 6 21:47 ..2982_06_02_21_47_53.299460680
@@ -203,14 +207,14 @@ atomically using [rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html)
203
207
然后通过使用 [ rename(2)] ( http://man7.org/linux/man-pages/man2/rename.2.html )
204
208
完成 ` ..data ` 符号链接的原子性更新。
205
209
210
+ {{< note >}}
206
211
<!--
207
212
A container using Downward API as a
208
213
[subPath](/docs/concepts/storage/volumes/#using-subpath) volume mount will not
209
214
receive Downward API updates.
210
215
-->
211
- {{< note >}}
212
216
如果容器以
213
- [ subPath] ( /zh-cn/docs/concepts/storage/volumes/#using-subpath ) 卷挂载方式来使用
217
+ [ subPath] ( /zh-cn/docs/concepts/storage/volumes/#using-subpath ) 卷挂载方式来使用
214
218
Downward API,则该容器无法收到更新事件。
215
219
{{< /note >}}
216
220
@@ -237,7 +241,8 @@ just one container:
237
241
## 存储容器字段 {#store-container-fields}
238
242
239
243
前面的练习中,你使用 downward API 使 Pod 级别的字段可以被 Pod 内正在运行的容器访问。
240
- 接下来这个练习,你将只传递由 Pod 定义的部分的字段到 Pod 内正在运行的容器中,但这些字段取自特定[ 容器] ( /zh-cn/docs/reference/kubernetes-api/workload-resources/pod-v1/#Container ) 而不是整个 Pod。
244
+ 接下来这个练习,你将只传递由 Pod 定义的部分的字段到 Pod 内正在运行的容器中,
245
+ 但这些字段取自特定[ 容器] ( /zh-cn/docs/reference/kubernetes-api/workload-resources/pod-v1/#Container ) 而不是整个 Pod。
241
246
下面是一个同样只有一个容器的 Pod 的清单:
242
247
243
248
{{< codenew file="pods/inject/dapi-volume-resources.yaml" >}}
@@ -260,16 +265,16 @@ Create the Pod:
260
265
-->
261
266
在这个清单中,你可以看到 Pod 有一个
262
267
[ ` downwardAPI ` 卷] ( /zh-cn/docs/concepts/storage/volumes/#downwardapi ) ,
263
- 并且这个会挂载到 Pod 内的单个容器的 ` /etc/podinfo ` 目录。
268
+ 并且这个卷会挂载到 Pod 内的单个容器的 ` /etc/podinfo ` 目录。
264
269
265
270
查看 ` downwardAPI ` 下面的 ` items ` 数组。
266
271
数组的每个元素定义一个 ` downwardAPI ` 卷。
267
272
268
273
第一个元素指定在名为 ` client-container ` 的容器中,
269
274
以 ` 1m ` 所指定格式的 ` limits.cpu ` 字段的值应推送到名为 ` cpu_limit ` 的文件中。
270
- ` divisor ` 字段是可选的,默认值为 ` 1 ` , 1 的除数表示 CPU 资源的核心或内存资源的字节 。
275
+ ` divisor ` 字段是可选的,默认值为 ` 1 ` 。 1 的除数表示 CPU 资源的核数或内存资源的字节数 。
271
276
272
- 创建Pod :
277
+ 创建 Pod :
273
278
274
279
``` shell
275
280
kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume-resources.yaml
@@ -298,7 +303,7 @@ cat /etc/podinfo/cpu_limit
298
303
You can use similar commands to view the `cpu_request`, `mem_limit` and
299
304
`mem_request` files.
300
305
-->
301
- 你可以使用同样的命令查看 ` cpu_request ` 、` mem_limit ` 和 ` mem_request ` 文件.
306
+ 你可以使用同样的命令查看 ` cpu_request ` 、` mem_limit ` 和 ` mem_request ` 文件。
302
307
303
308
<!-- discussion -->
304
309
0 commit comments