Kubernetes Downward API Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(8 intermediate revisions by the same user not shown)
Line 4: Line 4:


=Internal=
=Internal=
* [[Kubernetes_Concepts#Subjects|Kubernetes Concepts]]
* [[Kubernetes_Cluster_Configuration_Concepts#Downward_API|Cluster Configuration]]
* [[Kubernetes_Storage_Concepts#downwardAPI|Kubernetes Storage Concepts]]
* [[Kubernetes_Storage_Concepts#downwardAPI|Kubernetes Storage Concepts]]


=Overview=
=Overview=
Kubernetes is exposing pod information to the containers running inside the pod through files, which are projected in the container by a mechanism known as the Downward API.
Kubernetes is exposing pod information to the containers running inside the pod through [[#File_Projection|files]] or [[#Environment_Variable_Projection|environment variables]], which are projected in the container by a mechanism known as the Downward API. Individual pieces of information are declared as "items" under a "downwardAPI" volume declaration, and the corresponding content will be projected as individual files in the pod filesystem.


=Example=
The pieces of information to expose can be read from [[#Pod|pods]] or [[#Container|containers]].


This is how the pod name and namespace can be projected to be available to containers running inside the pod.  
=File Projection=
 
This is how the pod name and namespace can be projected as files available to containers running inside the pod.  


Declare a "downwardAPI" volume, conventionally named "podinfo" and mount it in the pod:
Declare a "downwardAPI" volume, conventionally named "podinfo" and mount it in the pod:
Line 26: Line 28:
     image: docker.io/ovidiufeodorov/loop:latest
     image: docker.io/ovidiufeodorov/loop:latest
     volumeMounts:
     volumeMounts:
       - name: podinfo
       - name: "podinfo"
         mountPath: /etc/podinfo
         mountPath: "/etc/podinfo"
   volumes:
   volumes:
   - name: podinfo
   - name: podinfo
Line 34: Line 36:
         - path: "metadata/name"
         - path: "metadata/name"
           fieldRef:
           fieldRef:
             fieldPath: metadata.name
             fieldPath: "metadata.name"
</syntaxhighlight>
</syntaxhighlight>


Note that individual downwardAPI items can declare a hierarchical path - the directories will be created automatically.
Note that individual downwardAPI items can declare a hierarchical path - the directories will be created automatically.
=Environment Variable Projection=
=Sources=
==Pod==
==Container==

Latest revision as of 20:47, 23 September 2021

External

Internal

Overview

Kubernetes is exposing pod information to the containers running inside the pod through files or environment variables, which are projected in the container by a mechanism known as the Downward API. Individual pieces of information are declared as "items" under a "downwardAPI" volume declaration, and the corresponding content will be projected as individual files in the pod filesystem.

The pieces of information to expose can be read from pods or containers.

File Projection

This is how the pod name and namespace can be projected as files available to containers running inside the pod.

Declare a "downwardAPI" volume, conventionally named "podinfo" and mount it in the pod:

apiVersion: v1
kind: Pod
metadata:
  name: loop
spec:
  containers:
  - name: loop
    image: docker.io/ovidiufeodorov/loop:latest
    volumeMounts:
      - name: "podinfo"
        mountPath: "/etc/podinfo"
  volumes:
  - name: podinfo
    downwardAPI:
      items:
        - path: "metadata/name"
          fieldRef:
            fieldPath: "metadata.name"

Note that individual downwardAPI items can declare a hierarchical path - the directories will be created automatically.

Environment Variable Projection

Sources

Pod

Container