<p>I have 3 delpoyments in my namespace. None of the deployments specify any resource limits for either CPU or memory. I am trying to set the default min and max using LimitRange for all pods and their containers(existing and future) in this namespace. I've deployed a LimitRange resource to the namespace as defined below. However, when I redeploy, the deployments fail with errors (as listed below)</p>
<p>LimitRange:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: "v1"
kind: "LimitRange"
metadata:
  name: "core-resource-limits"
  namespace: x
spec:
  limits:
    - type: "Pod"
      max:
        cpu: 1
        memory: 1Gi
      min:
        cpu: 2m
        memory: 50Mi
    - type: "Container"
      max:
        cpu: 1
        memory: 800Mi
      min:
        cpu: 1m
        memory: 50Mi
      default:
        cpu: 20m
        memory: 500Mi
      defaultRequest:
        cpu: 10m
        memory: 400Mi
      maxLimitRequestRatio:
        cpu: 4</code></pre>
</div>
</div>
</p>
<p><a href="https://i.stack.imgur.com/Y215F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y215F.png" alt="Error" /></a>
This is the error that I see</p>
<p>I don't understand where is 2040m coming from as its not defined in the LimitRange and its not defined in any of the deployments. Similarly all the other limit values. I have tried changing all these values to a bit higher/lower but I can't figure it out. Can someone explain what is wrong with this set of values?</p>
<p>Thanks</p>
<p>Edit:
All the pods are on the same node. The node limit are as follows:</p>
<ol>
<li>CPU requests: 2.86</li>
<li>CPU limits: 48.55</li>
<li>Memory requests: 7.459</li>
<li>Memory limits: 28.342</li>
</ol>

pyron_orion
<p>I would like to expand and explain in more detail what might be wrong here. Let's take a closer look at the overview of <a href="https://kubernetes.io/docs/concepts/policy/limit-range/" rel="nofollow noreferrer">Limit Range</a>:</p>
<ul>
<li><p>The administrator creates one <code>LimitRange</code> in one namespace.</p>
</li>
<li><p>Users create resources like <code>Pods</code>, <code>Containers</code>, and <code>PersistentVolumeClaims</code> in the namespace.</p>
</li>
<li><p>The <code>LimitRanger</code> admission controller enforces defaults and limits for all <code>Pods</code> and <code>Containers</code> that do not set compute resource requirements and tracks usage to ensure it does not exceed resource minimum, maximum and ratio defined in any <code>LimitRange</code> present in the namespace.</p>
</li>
<li><p>If creating or updating a resource (<code>Pod</code>, <code>Container</code>, <code>PersistentVolumeClaim</code>) that violates a <code>LimitRange</code> constraint, the request to the API server will fail with an HTTP status code 403 FORBIDDEN and a message explaining the constraint that have been violated.</p>
</li>
<li><p>If a <code>LimitRange</code> is activated in a namespace for compute resources like cpu and memory, users must specify requests or limits for those values. Otherwise, the system may reject Pod creation.</p>
</li>
<li><p><code>LimitRange</code> validations occurs only at Pod Admission stage, not on Running <code>Pods</code>.</p>
</li>
</ul>
<p>As already mentioned by @FritzDuchardt the error message clearly states that the limits are misconfigured or wrongly enforced. This leads us to two ways:</p>
<ul>
<li><p>Check if there are any other limits set at the <code>Pod</code> level (<code>kubectl edit pod &lt;pod_name&gt;</code>).</p>
</li>
<li><p>Within a namespace, a <code>Pod</code> or <code>Container</code> can consume as much CPU and memory as defined by the namespace's <a href="https://kubernetes.io/docs/concepts/policy/resource-quotas/" rel="nofollow noreferrer">resource quota</a>. Check if resource quotas are set with <code>kubectl describe quota</code>. In the case where the total limits of the namespace is less than the sum of the limits of the Pods/Containers, there may be contention for resources. In this case, the Containers or Pods will not be created.</p>
</li>
</ul>
<p>Here is an example of <a href="https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/#attempt-to-create-a-pod-that-exceeds-the-maximum-memory-constraint" rel="nofollow noreferrer">attempting to create a Pod that exceeds the maximum memory constraint</a> which represents the same result as you are experiencing.</p>
<p>I hope this explains the topic and potential issues in more detail.
Please let me know if that helps.</p>
