Skip to content

Latest commit

 

History

History
72 lines (63 loc) · 1.49 KB

nodes-cluster-resource-configure-request-limit.adoc

File metadata and controls

72 lines (63 loc) · 1.49 KB

Finding the memory request and limit from within a pod

An application wishing to dynamically discover its memory request and limit from within a pod should use the Downward API.

Procedure
  1. Configure the pod to add the MEMORY_REQUEST and MEMORY_LIMIT stanzas:

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: test
    image: fedora:latest
    command:
    - sleep
    - "3600"
    env:
    - name: MEMORY_REQUEST (1)
      valueFrom:
        resourceFieldRef:
          containerName: test
          resource: requests.memory
    - name: MEMORY_LIMIT (2)
      valueFrom:
        resourceFieldRef:
          containerName: test
          resource: limits.memory
    resources:
      requests:
        memory: 384Mi
      limits:
        memory: 512Mi
  1. Add this stanza to discover the application memory request value.

  2. Add this stanza to discover the application memory limit value.

    1. Create the pod:

      $ oc create -f <file-name>.yaml
    2. Access the pod using a remote shell:

      $ oc rsh test
    3. Check that the requested values were applied:

      $ env | grep MEMORY | sort
      MEMORY_LIMIT=536870912
      MEMORY_REQUEST=402653184
Note

The memory limit value can also be read from inside the container by the /sys/fs/cgroup/memory/memory.limit_in_bytes file.