I can't find this in the k8s documentation, I'm just wondering what are the default environment variables that are created in every container by k8s. Not user created defaults, but like (and this is just an example) maybe something like {service_name}_PORT
or something like that. I just wanna know what information is available in a container by default.

- 891
- 2
- 14
- 29
-
3You can take a quick look with `$ kubectl exec podName env ` – rrh Aug 19 '17 at 02:07
-
@oe18 that helped a lot thanks! – Luis F Hernandez Aug 22 '17 at 14:11
1 Answers
From the K8S Documentation:
Container information - ENV's
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 function call in libc.
The Pod name and namespace are available as environment variables.
These are the additional ENV's in a MiniKube cluster I have running:
HOSTNAME=something-api-234234234-skm70
SHLVL=1
HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_SERVICE_HOST=x.x.x.x
PWD=/
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 - ENV's
A list of all services that were running when a Container was created is available to that Container as environment variables. Those environment variables match the syntax of Docker links.
For a service named foo
that maps to a container port named bar
, the following variables are defined:
FOO_SERVICE_HOST=<the host the service is running on>
FOO_SERVICE_PORT=<the port the service is running on>

- 8,008
- 26
- 77
- 177

- 29,723
- 13
- 94
- 101
-
is that exhaustive? does it include all of the environment variables that are created? – Luis F Hernandez Aug 18 '17 at 14:53
-
I can't say for 100% but i've added the additional ENV's I have that aren't services. – ajtrichards Aug 19 '17 at 19:11
-
1You should also consider those variables on [discovering-services](https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services), as these are injected for `enableServiceLinks` (default value is true) – gonzalesraul Aug 20 '19 at 12:53
-
I can see a lot of environment variables which are not even defined in docker file or k8s manifest. – suresh Palemoni Aug 18 '20 at 06:07
-