services that can be queried from any EC2 instance to retrieve metadata about the EC2 instance itself. Similarly, AWS ECS provides APIs that can be queried by the con‐ tainers and retrieve information about the container cluster. The Kubernetes approach is even more elegant and easier to use. The  Downward API allows passing metadata about the Pod to the containers and the cluster through envi‐ ronment variables and files. These are the same mechanisms we used for passing application-related data from ConfigMaps and Secrets. But in this case, the data is not created by us. Instead, we specify the keys that interests us, and Kubernetes populates the values dynamically. Figure 13-1 gives an overview of how the Downward API injects resource and runtime information into interested Pods. The main point here is that with the Downward API, the metadata is injected into your Pod and made available locally. The application does not need to use a client and interact with the Kubernetes API and can remain Kubernetes-agnostic. Let’s see how easy it is to request metadata through environment variables in Example 13-1. Figure 13-1. Application introspection mechanisms Example 13-1. Environment variables from Downward API apiVersion : v1 kind : Pod metadata : name : random-generator spec : containers : -  image : k8spatterns/random-generator:1.0 name : random-generator env : -  name : POD_IP valueFrom : fieldRef : fieldPath : status.podIP 118  |  Chapter 13: Self Awareness