1

In java, you have min heap space (-Xms) and max heap space (-Xmx). Min heap space is allocated to the JVM from start, "max heap space" is the limit where the JVM will say "out of heap space" when reaching it.

Are there such different values (initial and limit) for a pod in Openshift/Kubernetes, or initial memory allocation is always equal to limit for some reason?

Tristan
  • 119
  • 3

1 Answers1

1

In Kubernetes, the mechanisms for controlling resources such as CPU and memory are requests and limits.

Requests are what the container is guaranteed to get. If a container requests a resource, Kubernetes will only schedule it on a node that can give it that resource.

Limits make sure a container never goes above a certain value. The container is only allowed to go up to the limit, and then it is restricted.

In case you don't specify your CPU limit:

  • The container can use all the processor resources available on the node on which it is running - because it has no upper bound on the CPU resources it can use.
  • The container is automatically assigned the default limit when it is running in a namespace that has a default CPU limit. If there is a need to change that one can use LimitRange.

In situation that you specified a CPU limit but CPU request is not specified Kubernetes automatically assigns a CPU request that matches the limit.

To learn more see this documentation and this article.

kkopczak
  • 111
  • 3
  • But I've read that if requests memory is not used, it's available for other containers. – Tristan Nov 06 '21 at 12:26
  • In [this documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) one can find: "If a Container specifies its own memory limit, but does not specify a memory request, Kubernetes automatically assigns a memory request that matches the limit." – kkopczak Nov 25 '21 at 18:17
  • But [this article](https://www.papertrail.com/solution/tips/kubernetes-logging-tips-to-avoid-memory-and-resource-issues/) should answer your question. "Without requests and limits set, pods will simply be managed on a first-come, first-served basis. Kubernetes will try to distribute RAM between all running pods equally, but if one pod tries to allocate more and more memory, Kubernetes may kick out other pods from the node to meet the demand. There’s nothing stopping pods from consuming all the free memory on the node." – kkopczak Nov 25 '21 at 18:17
  • Well, it does not answer the question, let's just a take a use case. My node is 2 Go, I have 2 pods which "requests" 1 Go each, but consumes only 300 Mo each. Is a third pod allowed to reuse unused memory ? – Tristan Nov 26 '21 at 11:52
  • Sorry for long time for response. Answering your question - the third one cannot do so. Take a look at [this doc](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#:~:text=How%20Pods%20with,in%20request%20rate.). Here one can read that it is impossible because of need of protection against a resource shortage on a node in case when resource usage later increases. – kkopczak Dec 06 '21 at 12:22
  • Ok thank, the documentation u provide answers perfectly to my use case, but now here is a slight variation : The node is 3 Go, and the 3rd pod requests 1 Go and it's limit is 2 Go. So it's allowed to start (sum of requests <= node capacity) and let's say it gets close to his limit (thus consuming memory that the 2 first "requested"), what happens here ? – Tristan Dec 06 '21 at 12:46
  • I am sory, I don't understand your question. Could you explain that? Or maybe consider [asking new question](https://serverfault.com/help/how-to-ask)? – kkopczak Dec 09 '21 at 20:54
  • well it's just a concrete example to illustrate the main question : My node is 3 Go, I have 2 pods which "requests" 1 Go each, but consumes only 300 Mo each. Now a 3rd pod requests 1 Go and it's limit is 2 Go. So it's allowed to start (sum of requests <= node capacity) and let's say it gets close to his limit (thus consuming memory that the 2 first "requested"), what happens here ? Is the 3rd pod limited to 1 Go even if the 2 first pods consumes only 300 Mo ? – Tristan Dec 10 '21 at 15:43
  • Hello @Tristan. Consider describing this use case in a separate question. It would be way more accessible and clear for the rest of community to help you out. – Wytrzymały Wiktor Dec 20 '21 at 09:48