Search code examples
kubernetesresourcesopenshiftthrottlingcgroups

Sharing CPU limits for containers within a pod


In Openshift/Kubernetes, I want to test how my application (pod) that consists of 2 containers performs on machines with different number of cores. The machine I have at hand has 32 cores, but I'd like to limit those to 4, 8, 16...

One way is using resource limits on the containers, but that would force me to set the ratio on each container; instead, I want to set resource limits for whole pod and let the containers compete on CPU. My feeling is that this should be possible, as the containers could belong to the same cgroup and therefore share the limits from the scheduler POV.

Would the LimitRange on pod do what I am looking for? LimitRange is project/namespace -scoped, is there a way to achieve the same with finer granularity (just for certain pods)?


Solution

  • As per documentation: resource constraints are only applicable on container level. You can however define different requests and limits to allow the container to burst beyond the amount defined in requests. But this comes with other implications see Quality of Service.

    The reason for this is that some resources such as memory cannot be competed about, as it works for CPU. Memory is either enough or too less. There is no such thing in Kubernetes as shared RAM. (If your are not explicitly call the relevant systemcalls)

    May I ask, what the use case for Pod internal CPU competition is?