ConfigMaps and secrets for example are suitable for passing data about application and their environment.

But for the variables that are not know before the pod starts, like the pod's IP address or name for example, we need to use another "medium" called the downwardAPI.

The downwardAPI is a kubernetes object that allows environment variables to be given attributes - that are know only after the pod starts - about the pod.
These values, couldn't be gathered if the pod is not running.

The downwardAPI can make the pod's environment variables accessible to the application running inside it, like the pod's IP address, pod's label, pod's name, or the resources requests of the pod like the CPU ,memory, ...

Below is an example of a pod using the downwardAPI:


When we run our pod, the NAME_POD and the ADDRESS_POD  get assigned the pod's name and the pod's IP address respectively.

This will allow the application running inside the pod to access the name and the IP address of the pod through the environment variables NAME_POD and ADDRESS_POD.

we can create the pod using the below command:


To print our environment variables, we use the below command on our running pod, and we use the "printenv" command once we are inside it as we can see below:

Brando Sabatini and Ikbal C ©. Powered by Blogger.