mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
106 lines
2.2 KiB
Plaintext
106 lines
2.2 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * nodes/nodes-containers-downward-api.adoc
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
[id="nodes-containers-downward-api-container-values-plugin_{context}"]
|
|
= Consuming container values using a volume plugin
|
|
|
|
You containers can consume API values using a volume plugin.
|
|
|
|
Containers can consume:
|
|
|
|
* Pod name
|
|
|
|
* Pod project/namespace
|
|
|
|
* Pod annotations
|
|
|
|
* Pod labels
|
|
|
|
.Procedure
|
|
|
|
To use the volume plugin:
|
|
|
|
. Create a new pod spec that contains the environment variables you want the container to consume:
|
|
|
|
.. Create a `volume-pod.yaml` file similar to the following:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
kind: Pod
|
|
apiVersion: v1
|
|
metadata:
|
|
labels:
|
|
zone: us-east-coast
|
|
cluster: downward-api-test-cluster1
|
|
rack: rack-123
|
|
name: dapi-volume-test-pod
|
|
annotations:
|
|
annotation1: "345"
|
|
annotation2: "456"
|
|
spec:
|
|
securityContext:
|
|
runAsNonRoot: true
|
|
seccompProfile:
|
|
type: RuntimeDefault
|
|
containers:
|
|
- name: volume-test-container
|
|
image: gcr.io/google_containers/busybox
|
|
command: ["sh", "-c", "cat /tmp/etc/pod_labels /tmp/etc/pod_annotations"]
|
|
volumeMounts:
|
|
- name: podinfo
|
|
mountPath: /tmp/etc
|
|
readOnly: false
|
|
securityContext:
|
|
allowPrivilegeEscalation: false
|
|
capabilities:
|
|
drop: [ALL]
|
|
volumes:
|
|
- name: podinfo
|
|
downwardAPI:
|
|
defaultMode: 420
|
|
items:
|
|
- fieldRef:
|
|
fieldPath: metadata.name
|
|
path: pod_name
|
|
- fieldRef:
|
|
fieldPath: metadata.namespace
|
|
path: pod_namespace
|
|
- fieldRef:
|
|
fieldPath: metadata.labels
|
|
path: pod_labels
|
|
- fieldRef:
|
|
fieldPath: metadata.annotations
|
|
path: pod_annotations
|
|
restartPolicy: Never
|
|
# ...
|
|
----
|
|
|
|
.. Create the pod from the `volume-pod.yaml` file:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f volume-pod.yaml
|
|
----
|
|
|
|
.Verification
|
|
|
|
* Check the container's logs and verify the presence of the configured fields:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc logs -p dapi-volume-test-pod
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
cluster=downward-api-test-cluster1
|
|
rack=rack-123
|
|
zone=us-east-coast
|
|
annotation1=345
|
|
annotation2=456
|
|
kubernetes.io/config.source=api
|
|
----
|