Skip to content

Commit fc0e066

Browse files
authored
Merge pull request #32241 from tengqm/tweak-downwardapi-vol
Tweak the downward API volume task page
2 parents e05ea36 + 6149835 commit fc0e066

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

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

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,26 @@ weight: 40
66

77
<!-- overview -->
88

9-
This page shows how a Pod can use a DownwardAPIVolumeFile to expose information
10-
about itself to Containers running in the Pod. A DownwardAPIVolumeFile can expose
11-
Pod fields and Container fields.
12-
13-
14-
9+
This page shows how a Pod can use a
10+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
11+
to expose information about itself to Containers running in the Pod.
12+
A `DownwardAPIVolumeFile` can expose Pod fields and Container fields.
1513

1614
## {{% heading "prerequisites" %}}
1715

18-
1916
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
2017

21-
22-
2318
<!-- steps -->
2419

2520
## The Downward API
2621

2722
There are two ways to expose Pod and Container fields to a running Container:
2823

2924
* [Environment variables](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api)
30-
* Volume Files
25+
* Volume files
3126

3227
Together, these two ways of exposing Pod and Container fields are called the
33-
*Downward API*.
28+
"Downward API".
3429

3530
## Store Pod fields
3631

@@ -60,13 +55,13 @@ Create the Pod:
6055
kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume.yaml
6156
```
6257

63-
Verify that the Container in the Pod is running:
58+
Verify that the container in the Pod is running:
6459

6560
```shell
6661
kubectl get pods
6762
```
6863

69-
View the Container's logs:
64+
View the container's logs:
7065

7166
```shell
7267
kubectl logs kubernetes-downwardapi-volume-example
@@ -83,7 +78,7 @@ build="two"
8378
builder="john-doe"
8479
```
8580

86-
Get a shell into the Container that is running in your Pod:
81+
Get a shell into the container that is running in your Pod:
8782

8883
```shell
8984
kubectl exec -it kubernetes-downwardapi-volume-example -- sh
@@ -136,8 +131,7 @@ total 8
136131

137132
Using symbolic links enables dynamic atomic refresh of the metadata; updates are
138133
written to a new temporary directory, and the `..data` symlink is updated
139-
atomically using
140-
[rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html).
134+
atomically using [rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html).
141135

142136
{{< note >}}
143137
A container using Downward API as a
@@ -153,17 +147,19 @@ Exit the shell:
153147

154148
## Store Container fields
155149

156-
The preceding exercise, you stored Pod fields in a DownwardAPIVolumeFile.
150+
The preceding exercise, you stored Pod fields in a
151+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)..
157152
In this next exercise, you store Container fields. Here is the configuration
158153
file for a Pod that has one Container:
159154

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

162-
In the configuration file, you can see that the Pod has a `downwardAPI` Volume,
163-
and the Container mounts the Volume at `/etc/podinfo`.
157+
In the configuration file, you can see that the Pod has a
158+
[`downwardAPI` volume](/concepts/storage/volumes/#downwardapi),
159+
and the Container mounts the volume at `/etc/podinfo`.
164160

165161
Look at the `items` array under `downwardAPI`. Each element of the array is a
166-
DownwardAPIVolumeFile.
162+
[`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core).
167163

168164
The first element specifies that in the Container named `client-container`,
169165
the value of the `limits.cpu` field in the format specified by `1m` should be
@@ -176,7 +172,7 @@ Create the Pod:
176172
kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume-resources.yaml
177173
```
178174

179-
Get a shell into the Container that is running in your Pod:
175+
Get a shell into the container that is running in your Pod:
180176

181177
```shell
182178
kubectl exec -it kubernetes-downwardapi-volume-example-2 -- sh
@@ -187,46 +183,56 @@ In your shell, view the `cpu_limit` file:
187183
```shell
188184
/# cat /etc/podinfo/cpu_limit
189185
```
186+
190187
You can use similar commands to view the `cpu_request`, `mem_limit` and
191188
`mem_request` files.
192189

193-
194-
195190
<!-- discussion -->
196191

192+
<!-- TODO: This section should be extracted out of the task page. -->
197193
## Capabilities of the Downward API
198194

199195
The following information is available to containers through environment
200196
variables and `downwardAPI` volumes:
201197

202198
* Information available via `fieldRef`:
199+
203200
* `metadata.name` - the pod's name
204201
* `metadata.namespace` - the pod's namespace
205202
* `metadata.uid` - the pod's UID
206-
* `metadata.labels['<KEY>']` - the value of the pod's label `<KEY>` (for example, `metadata.labels['mylabel']`)
207-
* `metadata.annotations['<KEY>']` - the value of the pod's annotation `<KEY>` (for example, `metadata.annotations['myannotation']`)
203+
* `metadata.labels['<KEY>']` - the value of the pod's label `<KEY>`
204+
(for example, `metadata.labels['mylabel']`)
205+
* `metadata.annotations['<KEY>']` - the value of the pod's annotation `<KEY>`
206+
(for example, `metadata.annotations['myannotation']`)
207+
208208
* Information available via `resourceFieldRef`:
209+
209210
* A Container's CPU limit
210211
* A Container's CPU request
211212
* A Container's memory limit
212213
* A Container's memory request
213-
* A Container's hugepages limit (providing that the `DownwardAPIHugePages` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
214-
* A Container's hugepages request (providing that the `DownwardAPIHugePages` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
214+
* A Container's hugepages limit (provided that the `DownwardAPIHugePages`
215+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
216+
* A Container's hugepages request (provided that the `DownwardAPIHugePages`
217+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled)
215218
* A Container's ephemeral-storage limit
216219
* A Container's ephemeral-storage request
217220

218221
In addition, the following information is available through
219222
`downwardAPI` volume `fieldRef`:
220223

221-
* `metadata.labels` - all of the pod's labels, formatted as `label-key="escaped-label-value"` with one label per line
222-
* `metadata.annotations` - all of the pod's annotations, formatted as `annotation-key="escaped-annotation-value"` with one annotation per line
224+
* `metadata.labels` - all of the pod's labels, formatted as `label-key="escaped-label-value"`
225+
with one label per line
226+
* `metadata.annotations` - all of the pod's annotations, formatted as
227+
`annotation-key="escaped-annotation-value"` with one annotation per line
223228

224229
The following information is available through environment variables:
225230

226231
* `status.podIP` - the pod's IP address
227-
* `spec.serviceAccountName` - the pod's service account name, available since v1.4.0-alpha.3
228-
* `spec.nodeName` - the node's name, available since v1.4.0-alpha.3
229-
* `status.hostIP` - the node's IP, available since v1.7.0-alpha.1
232+
* `spec.serviceAccountName` - the pod's service account name
233+
* `spec.nodeName` - the name of the node to which the scheduler always attempts to
234+
schedule the pod
235+
* `status.hostIP` - the IP of the node to which the Pod is assigned
230236

231237
{{< note >}}
232238
If CPU and memory limits are not specified for a Container, the
@@ -241,7 +247,7 @@ basis. For more information, see
241247

242248
## Motivation for the Downward API
243249

244-
It is sometimes useful for a Container to have information about itself, without
250+
It is sometimes useful for a container to have information about itself, without
245251
being overly coupled to Kubernetes. The Downward API allows containers to consume
246252
information about themselves or the cluster without using the Kubernetes client
247253
or API server.
@@ -252,19 +258,17 @@ application, but that is tedious and error prone, and it violates the goal of lo
252258
coupling. A better option would be to use the Pod's name as an identifier, and
253259
inject the Pod's name into the well-known environment variable.
254260

255-
256-
257-
258261
## {{% heading "whatsnext" %}}
259262

260-
261-
* [PodSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
262-
* [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
263-
* [DownwardAPIVolumeSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumesource-v1-core)
264-
* [DownwardAPIVolumeFile](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
265-
* [ResourceFieldSelector](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcefieldselector-v1-core)
266-
267-
268-
269-
263+
* Check the [`PodSpec`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
264+
API definition which defines the desired state of a Pod.
265+
* Check the [`Volume`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
266+
API definition which defines a generic volume in a Pod for containers to access.
267+
* Check the [`DownwardAPIVolumeSource`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumesource-v1-core)
268+
API definition which defines a volume that contains Downward API information.
269+
* Check the [`DownwardAPIVolumeFile`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#downwardapivolumefile-v1-core)
270+
API definition which contains references to object or resource fields for
271+
populating a file in the Downward API volume.
272+
* Check the [`ResourceFieldSelector`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcefieldselector-v1-core)
273+
API definition which specifies the container resources and their output format.
270274

0 commit comments

Comments
 (0)