// Module included in the following assemblies:
//
// * scalability_and_performance/what-huge-pages-do-and-how-they-are-consumed-by-apps.adoc

:file-name: hugepages-volume-pod.yaml

:_mod-docs-content-type: PROCEDURE
[id="consuming-huge-pages-resource-using-the-downward-api_{context}"]
= Consuming huge pages resources using the Downward API

[role="_abstract"]
To inject information about the huge pages resources consumed by a container, use the Downward API.

You can inject the resource allocation as environment variables, a volume plugin, or both. Applications that you develop and run in the container can determine the resources that are available by reading the environment variables or files in the specified volumes.

.Procedure

. Create a `{file-name}` file that is similar to the following example:
+
[source,yaml]
----
apiVersion: v1
kind: Pod
metadata:
  generateName: hugepages-volume-
  labels:
    app: hugepages-example
spec:
  containers:
  - securityContext:
      capabilities:
        add: [ "IPC_LOCK" ]
    image: rhel7:latest
    command:
    - sleep
    - inf
    name: example
    volumeMounts:
    - mountPath: /dev/hugepages
      name: hugepage
    - mountPath: /etc/podinfo
      name: podinfo
    resources:
      limits:
        hugepages-1Gi: 2Gi
        memory: "1Gi"
        cpu: "1"
      requests:
        hugepages-1Gi: 2Gi
    env:
    - name: REQUESTS_HUGEPAGES_1GI
      valueFrom:
        resourceFieldRef:
          containerName: example
          resource: requests.hugepages-1Gi
  volumes:
  - name: hugepage
    emptyDir:
      medium: HugePages
  - name: podinfo
    downwardAPI:
      items:
        - path: "hugepages_1G_request"
          resourceFieldRef:
            containerName: example
            resource: requests.hugepages-1Gi
            divisor: 1Gi
----
+
where:
+
`spec.containers.securityContext.env.name`:: Specifies what resource to read and use from `requests.hugepages-1Gi` and expose the value as the `REQUESTS_HUGEPAGES_1GI` environment variable.
`spec.volumes.name.items.path`:: Specifies what resource to read and use from `requests.hugepages-1Gi` and expose the value as the file `/etc/podinfo/hugepages_1G_request`.

. Create the pod from the `{file-name}` file by entering the following command:
+
[source,terminal,subs="attributes+"]
----
$ oc create -f {file-name}
----

.Verification

. Check the value of the `REQUESTS_HUGEPAGES_1GI` environment variable:
+
[source,terminal]
----
$ oc exec -it $(oc get pods -l app=hugepages-example -o jsonpath='{.items[0].metadata.name}') \
     -- env | grep REQUESTS_HUGEPAGES_1GI
----
+
.Example output
[source,terminal]
----
REQUESTS_HUGEPAGES_1GI=2147483648
----

. Check the value of the `/etc/podinfo/hugepages_1G_request` file:
+
[source,terminal]
----
$ oc exec -it $(oc get pods -l app=hugepages-example -o jsonpath='{.items[0].metadata.name}') \
     -- cat /etc/podinfo/hugepages_1G_request
----
+
.Example output
[source,terminal]
----
2
----

:!file-name:
