0

Assume I have a pod with 3 containers: X, Y, and Z.

K8S can set a cpu limit for each container in a pod. However, if I set 1000M CPU limit to each container, then any container cannot use more than 1000M CPU even if the other two are ilde, which is not what I want.

I want to set a CPU quota of 3000M to the pod, rather than to each container. For example, if X & Y are idle, Z can use 3000M CPU; if X is using 1500M CPU, Y is using 1000M CPU, then Z can only use 500M CPU.

So, my question is:

How to share a CPU quota among multiple containers?

xmllmx
  • 39,765
  • 26
  • 162
  • 323

2 Answers2

2

I must set limits because I must pay for my usage to the cloud provider.

In such a case, I would recommend you to use Vertical-Pod-AutoScaler along with a Limit Range.

A LimitRange provides constraints that can:

  • Enforce minimum and maximum compute resources usage per Pod or Container in a namespace.

And the VPA will try to cap recommendations between min and max of limitRanges based on the current usages.

N.B.: Make sure you have metrics-server installed in your cluster to enable the VPA.

Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
  • 2
    This can help shift the limits over time but it won't help with short term bursting. VPA is looking at rolling averages over days, not seconds. – coderanger Jul 28 '21 at 05:47
0

Just don't set a CPU limit at all. Or set it to some higher value. Setting a CPU limit should only happen in situations where it's known to be needed, in general they do more harm than good.

coderanger
  • 52,400
  • 4
  • 52
  • 75