Description
What would you like to be added:
It would be nice to pass a process a number that is a bit lower than the container memory limit so that its garbage collection or memory management can use that limit.
For example:
- setting
GOMEMLIMIT
or settingNODEMEMLIMIT
- setting
NODE_OPTS=--max-old-space-size=$(NODEMEMLIMIT)
would be useful. - setting
JAVA_MEM_LIMIT
and passing-Xmx$(JAVA_MEM_LIMIT)M
Currently you can use envFrom.resourceFieldRef
to "copy" a resource request or limit to an environment variable, but you can only multiply the value by some power of 1000 or 1024 by specifying divisor
.
Why is this needed:
This would make it possible to pass a memory limit into a process inside the container that is based on the container resource request or limit but less.
For example, when specifying node's --max-old-space-size
or Java's -Xmx
parameter, setting it equal to the memory limit of the container will be a problem, because the process actually uses more memory than what you provided as a parameter.
Potential Solutions
- If we could specify a
divisor
like1.5Mi
then it would result in a number of megabytes equal to roughly 2 thirds of the available memory, leaving some extra for the other heaps. - Add another field like
scale
ormultiplier
toenfFrom.resourceFieldRef
which is multiplied by the input value to get the env var value - Allow arithmetic in the existing env var expansion system - where currently you can only do
$(SOME_VAR)
in the command line, additionally support something like$(SOME_VAR - 100)
- Allow using a go template or some simple templating/expression language to actually fill out the env var with prefix and suffix, like
--max-old-space-size={{ value * 800 }}M
Workarounds
- Create an admission webhook that does one of the above without changing the kubernetes core features
- If the container uses bash, you could run a command like
bash -c 'NODE_OPTIONS=---max-old-space-size=$(($MEMORY_LIMIT-500)) ...
or create your own entrypoint wrapper (maybe a shell script) that calculates the env vars before running the actual command
Metadata
Metadata
Assignees
Labels
Type
Projects
Status