2015-07-14 00:13:09 +00:00
|
|
|
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
|
|
|
|
|
|
|
<!-- BEGIN STRIP_FOR_RELEASE -->
|
|
|
|
|
2015-07-15 00:28:47 +00:00
|
|
|
![WARNING](http://kubernetes.io/img/warning.png)
|
|
|
|
![WARNING](http://kubernetes.io/img/warning.png)
|
|
|
|
![WARNING](http://kubernetes.io/img/warning.png)
|
2015-07-13 22:15:35 +00:00
|
|
|
|
|
|
|
<h1>PLEASE NOTE: This document applies to the HEAD of the source
|
2015-07-14 00:13:09 +00:00
|
|
|
tree only. If you are using a released version of Kubernetes, you almost
|
|
|
|
certainly want the docs that go with that version.</h1>
|
|
|
|
|
|
|
|
<strong>Documentation for specific releases can be found at
|
|
|
|
[releases.k8s.io](http://releases.k8s.io).</strong>
|
|
|
|
|
2015-07-15 00:28:47 +00:00
|
|
|
![WARNING](http://kubernetes.io/img/warning.png)
|
|
|
|
![WARNING](http://kubernetes.io/img/warning.png)
|
|
|
|
![WARNING](http://kubernetes.io/img/warning.png)
|
2015-07-13 22:15:35 +00:00
|
|
|
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- END STRIP_FOR_RELEASE -->
|
|
|
|
|
|
|
|
<!-- END MUNGE: UNVERSIONED_WARNING -->
|
2015-05-04 17:31:36 +00:00
|
|
|
# Downward API example
|
|
|
|
|
|
|
|
Following this example, you will create a pod with a containers that consumes the pod's name and
|
2015-07-16 21:54:28 +00:00
|
|
|
namespace using the [downward API](../downward-api.md).
|
2015-05-04 17:31:36 +00:00
|
|
|
|
|
|
|
## Step Zero: Prerequisites
|
|
|
|
|
|
|
|
This example assumes you have a Kubernetes cluster installed and running, and that you have
|
|
|
|
installed the ```kubectl``` command line tool somewhere in your path. Please see the [getting
|
2015-07-14 16:37:37 +00:00
|
|
|
started](../../../docs/getting-started-guides/) for installation instructions for your platform.
|
2015-05-04 17:31:36 +00:00
|
|
|
|
|
|
|
## Step One: Create the pod
|
|
|
|
|
|
|
|
Containers consume the downward API using environment variables. The downward API allows
|
|
|
|
containers to be injected with the name and namespace of the pod the container is in.
|
|
|
|
|
2015-05-23 01:51:12 +00:00
|
|
|
Use the [`examples/downward-api/dapi-pod.yaml`](dapi-pod.yaml) file to create a Pod with a container that consumes the
|
2015-05-04 17:31:36 +00:00
|
|
|
downward API.
|
|
|
|
|
|
|
|
```shell
|
2015-07-15 17:42:59 +00:00
|
|
|
$ kubectl create -f docs/user-guide/downward-api/dapi-pod.yaml
|
2015-05-04 17:31:36 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Examine the logs
|
|
|
|
|
|
|
|
This pod runs the `env` command in a container that consumes the downward API. You can grep
|
|
|
|
through the pod logs to see that the pod was injected with the correct values:
|
|
|
|
|
|
|
|
```shell
|
2015-06-09 21:30:53 +00:00
|
|
|
$ kubectl logs dapi-test-pod | grep POD_
|
2015-05-04 17:31:36 +00:00
|
|
|
2015-04-30T20:22:18.568024817Z POD_NAME=dapi-test-pod
|
|
|
|
2015-04-30T20:22:18.568087688Z POD_NAMESPACE=default
|
|
|
|
```
|
2015-05-14 22:12:45 +00:00
|
|
|
|
|
|
|
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
2015-07-14 16:37:37 +00:00
|
|
|
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/downward-api/README.md?pixel)]()
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- END MUNGE: GENERATED_ANALYTICS -->
|