<p>Assume I have a pod with 3 containers: <em><strong><code>X</code></strong></em>, <em><strong><code>Y</code></strong></em>, and <em><strong><code>Z</code></strong></em>.</p>
<p><strong>K8S</strong> can set a cpu limit for each container in a pod. However, if I set <code>1000M</code> CPU limit to each container, then any container cannot use more than <code>1000M</code> CPU even if the other two are ilde, which is not what I want.</p>
<p>I want to set a CPU quota of <code>3000M</code> to the pod, rather than to each container. For example, if <em><strong><code>X</code></strong></em> &amp; <em><strong><code>Y</code></strong></em> are idle, <em><strong><code>Z</code></strong></em> can use <code>3000M</code> CPU; if <em><strong><code>X</code></strong></em> is using <code>1500M</code> CPU, <em><strong><code>Y</code></strong></em> is using <code>1000M</code> CPU, then <em><strong><code>Z</code></strong></em> can only use <code>500M</code> CPU.</p>
<p>So, my question is:</p>
<p><strong>How to share a CPU quota among multiple containers?</strong></p>

xmllmx
<blockquote>
<p>I must set limits because I must pay for my usage to the cloud provider.</p>
</blockquote>
<p>In such a case, I would recommend you to use <a href="https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler#limits-control" rel="nofollow noreferrer">Vertical-Pod-AutoScaler</a> along with a <a href="https://kubernetes.io/docs/concepts/policy/limit-range/" rel="nofollow noreferrer">Limit Range</a>.</p>
<p>A <code>LimitRange</code> provides constraints that can:</p>
<ul>
<li>Enforce minimum and maximum compute resources usage per Pod or Container in a namespace.</li>
</ul>
<p>And the VPA will try to cap recommendations between min and max of <code>limitRanges</code> based on the current usages.</p>
<p><strong>N.B.:</strong> Make sure you have <a href="https://github.com/kubernetes-sigs/metrics-server" rel="nofollow noreferrer">metrics-server</a> installed in your cluster to enable the VPA.</p>
