An application wishing to dynamically discover its memory request and limit from within a pod should use the Downward API.
Procedure
-
Configure the pod to add the
MEMORY_REQUEST
andMEMORY_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
-
Add this stanza to discover the application memory request value.
-
Add this stanza to discover the application memory limit value.
-
Create the pod:
$ oc create -f <file-name>.yaml
-
Access the pod using a remote shell:
$ oc rsh test
-
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
|