Kubernetes Downward API Concepts: Difference between revisions
Jump to navigation
Jump to search
Line 26: | Line 26: | ||
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 34: | ||
- 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. |
Revision as of 23:30, 18 June 2020
External
- https://kubernetes.io/docs/concepts/storage/volumes/#downwardapi
- https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/
Internal
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.
Example
This is how the pod name and namespace can be projected to be 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.