Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8e5186a1
Commit
8e5186a1
authored
Jul 10, 2015
by
Rohit Jnagal
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10794 from thockin/docs-downapi
Better docs for downward API
parents
2a3ed99a
e3fb54ea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
17 deletions
+44
-17
downward_api.md
docs/downward_api.md
+44
-17
No files found.
docs/downward_api.md
View file @
8e5186a1
# Downward API
# Downward API
The downward API allows containers to consume information about the system without coupling to the
It is sometimes useful for a container to have information about itself, but we
want to be careful not to over-couple containers to Kubernetes. The downward
API allows containers to consume information about themselves or the system and
expose that information how they want it, without necessarily coupling to the
kubernetes client or REST API.
kubernetes client or REST API.
### Capabilities
An example of this is a "legacy" app that is already written assuming
that a particular environment variable will hold a unique identifier. While it
is often possible to "wrap" such applications, this is tedious and error prone,
and violates the goal of low coupling. Instead, the user should be able to use
the Pod's name, for example, and inject it into this well-known variable.
Containers can consume the following information via the downward API:
## Capabilities
*
Their pod's name
The following information is available to a
`Pod`
through the the downward API:
*
Their pod's namespace
### Consuming information about a pod in a container
*
The pod's name
*
The pod's namespace
Containers consume information from the downward API using environment variables. In the future,
More information will be exposed through this same API over time.
containers will also be able to consume the downward API via a volume plugin. The
`valueFrom`
field of an environment variable allows you to specify an
`ObjectFieldSelector`
to select fields
from the pod's definition. The
`ObjectFieldSelector`
has an
`apiVersion`
field and a
`fieldPath`
field. The
`fieldPath`
field is an expression designating a field on the pod. The
`apiVersion`
field is the version of the API schema that the
`fieldPath`
is written in terms of. If the
`apiVersion`
field is not specified it is defaulted to the API version of the enclosing object.
##
# Example: consuming the downward API
##
Exposing pod information into a container
This is an example of a pod that consumes its name and namespace via the downward API:
Containers consume information from the downward API using environment
variables. In the future, containers will also be able to consume the downward
API via a volume plugin.
### Environment variables
Most environment variables in the Kubernetes API use the
`value`
field to carry
simple values. However, the alternate
`valueFrom`
field allows you to specify
a
`fieldRef`
to select fields from the pod's definition. The
`fieldRef`
field
is a structure that has an
`apiVersion`
field and a
`fieldPath`
field. The
`fieldPath`
field is an expression designating a field of the pod. The
`apiVersion`
field is the version of the API schema that the
`fieldPath`
is
written in terms of. If the
`apiVersion`
field is not specified it is
defaulted to the API version of the enclosing object.
The
`fieldRef`
is evaluated and the resulting value is used as the value for
the environment variable. This allows users to publish their pod's name in any
environment variable they want.
## Example
This is an example of a pod that consumes its name and namespace via the
downward API:
```
yaml
```
yaml
apiVersion
:
v1
apiVersion
:
v1
...
@@ -35,16 +58,20 @@ spec:
...
@@ -35,16 +58,20 @@ spec:
image
:
gcr.io/google_containers/busybox
image
:
gcr.io/google_containers/busybox
command
:
[
"
/bin/sh"
,
"
-c"
,
"
env"
]
command
:
[
"
/bin/sh"
,
"
-c"
,
"
env"
]
env
:
env
:
-
name
:
POD_NAME
-
name
:
MY_
POD_NAME
valueFrom
:
valueFrom
:
fieldRef
:
fieldRef
:
fieldPath
:
metadata.name
fieldPath
:
metadata.name
-
name
:
POD_NAMESPACE
-
name
:
MY_
POD_NAMESPACE
valueFrom
:
valueFrom
:
fieldRef
:
fieldRef
:
fieldPath
:
metadata.namespace
fieldPath
:
metadata.namespace
restartPolicy
:
Never
restartPolicy
:
Never
```
```
Some more thorough examples:
*
[
environment variables
](
../examples/environment-guide
)
*
[
downward API
](
../examples/downward-api
)
[

]()
[

]()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment