A user can change certain metadata such as labels and annotations while a Pod is running. Unless the Pod is restarted, environment variables will not reflect such a change. But  downwardAPI  volumes can reflect updates to labels and annotations. In addition to the individual fields described previously,  downwardAPI  volumes can cap‐ ture all Pod labels and annotations into files with  metadata.labels  and  meta data.annotations  references. Example 13-2 shows how such volumes can be used. With volumes, if the metadata changes while the Pod is running, it is reflected in the volume files. But it is still up to the consuming application to detect the file change and read the updated data accordingly. If such a functionality is not implemented in the application, a Pod restart still might be required. The  annotations  file holds all annotations in the same format as the labels. The file  labels  contain all labels, line by line, in the format  name=value . This file gets updated when labels are changing. Values from the Downward API can be mounted as files into the Pod. Example 13-2. Downward API through volumes apiVersion : v1 kind : Pod metadata : name : random-generator spec : containers : -  image : k8spatterns/random-generator:1.0 name : random-generator volumeMounts : -  name : pod-info mountPath : /pod-info volumes : -  name : pod-info downwardAPI : items : -  path : labels fieldRef : fieldPath : metadata.labels -  path : annotations fieldRef : fieldPath : metadata.annotations 120  |  Chapter 13: Self Awareness