2017-04-25 17:36:59 +00:00
|
|
|
|
---
|
2018-02-27 18:51:46 +00:00
|
|
|
|
reviewers:
|
2017-04-25 17:36:59 +00:00
|
|
|
|
- mikedanese
|
|
|
|
|
- thockin
|
|
|
|
|
title: Container Environment Variables
|
2018-05-05 16:00:51 +00:00
|
|
|
|
content_template: templates/concept
|
2018-06-06 23:51:26 +00:00
|
|
|
|
weight: 20
|
2017-04-25 17:36:59 +00:00
|
|
|
|
---
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% capture overview %}}
|
2017-04-25 17:36:59 +00:00
|
|
|
|
|
|
|
|
|
This page describes the resources available to Containers in the Container environment.
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% /capture %}}
|
2017-04-25 17:36:59 +00:00
|
|
|
|
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% capture body %}}
|
2017-04-25 17:36:59 +00:00
|
|
|
|
|
|
|
|
|
## Container environment
|
|
|
|
|
|
|
|
|
|
The Kubernetes Container environment provides several important resources to Containers:
|
|
|
|
|
|
2017-09-23 10:41:18 +00:00
|
|
|
|
* A filesystem, which is a combination of an [image](/docs/concepts/containers/images/) and one or more [volumes](/docs/concepts/storage/volumes/).
|
2017-04-25 17:36:59 +00:00
|
|
|
|
* Information about the Container itself.
|
|
|
|
|
* Information about other objects in the cluster.
|
|
|
|
|
|
|
|
|
|
### Container information
|
|
|
|
|
|
|
|
|
|
The *hostname* of a Container is the name of the Pod in which the Container is running.
|
|
|
|
|
It is available through the `hostname` command or the
|
|
|
|
|
[`gethostname`](http://man7.org/linux/man-pages/man2/gethostname.2.html)
|
|
|
|
|
function call in libc.
|
|
|
|
|
|
|
|
|
|
The Pod name and namespace are available as environment variables through the
|
2017-09-26 02:14:20 +00:00
|
|
|
|
[downward API](/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/).
|
2017-04-25 17:36:59 +00:00
|
|
|
|
|
|
|
|
|
User defined environment variables from the Pod definition are also available to the Container,
|
|
|
|
|
as are any environment variables specified statically in the Docker image.
|
|
|
|
|
|
|
|
|
|
### Cluster information
|
|
|
|
|
|
2017-08-12 03:47:35 +00:00
|
|
|
|
A list of all services that were running when a Container was created is available to that Container as environment variables.
|
2017-04-25 17:36:59 +00:00
|
|
|
|
Those environment variables match the syntax of Docker links.
|
|
|
|
|
|
2018-02-27 19:28:45 +00:00
|
|
|
|
For a service named *foo* that maps to a Container named *bar*,
|
2017-04-25 17:36:59 +00:00
|
|
|
|
the following variables are defined:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
FOO_SERVICE_HOST=<the host the service is running on>
|
|
|
|
|
FOO_SERVICE_PORT=<the port the service is running on>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Services have dedicated IP addresses and are available to the Container via DNS,
|
2018-05-05 16:00:51 +00:00
|
|
|
|
if [DNS addon](http://releases.k8s.io/{{< param "githubbranch" >}}/cluster/addons/dns/) is enabled.
|
2017-04-25 17:36:59 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% /capture %}}
|
2017-04-25 17:36:59 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% capture whatsnext %}}
|
2017-04-25 17:36:59 +00:00
|
|
|
|
|
2017-05-02 21:12:48 +00:00
|
|
|
|
* Learn more about [Container lifecycle hooks](/docs/concepts/containers/container-lifecycle-hooks/).
|
2017-04-25 17:36:59 +00:00
|
|
|
|
* Get hands-on experience
|
|
|
|
|
[attaching handlers to Container lifecycle events](/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/).
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% /capture %}}
|