<p>I'm having trouble in creating the pod using ResourceQuota and LimitRange. </p>

<p>The ResourceQuota has limit cpu=2,memory=2Gi &amp; requests cpu=1,memory=1Gi defined for CPU &amp; memory 
The LimitRange has default requests and default limits, both having cpu=1,memory=1Gi which is within what is defined in the ResourceQuota .</p>

<p>While creating the pod using only limits(cpu=2,memory=2Gi) without requests(cpu,memory), it is failing with 
<code>forbidden: exceeded quota: compute-resources, requested: requests.cpu=2,requests.memory=2Gi, used: requests.cpu=0,requests.memory=0, limited: requests.cpu=1,requests.memory=1Gi</code></p>

<p>but as per the default request defined in LimitRange it is  cpu=1,memory=1Gi not sure from where it is taking requests.cpu=2,requests.memory=2Gi</p>

<p>As I understand while creating the pod if resource requests is not mentioned, it should take it from LimitRange default requests which is within the range, not sure why it is failing.</p>

<p>please help here</p>

<pre><code>cloud_user@master-node:~$  k describe limitrange default-limitrange
Name:       default-limitrange
Namespace:  default
Type        Resource  Min  Max  Default Request  Default Limit  Max Limit/Request Ratio
----        --------  ---  ---  ---------------  -------------  -----------------------
Container   memory    -    -    1Gi              1Gi            -
Container   cpu       -    -    1                1              -
</code></pre>

<pre><code>cloud_user@master-node:~$ k describe resourcequota compute-resources
Name:            compute-resources
Namespace:       default
Resource         Used  Hard
--------         ----  ----
limits.cpu       0     2
limits.memory    0     2Gi
pods             0     2
requests.cpu     0     1
requests.memory  0     1Gi
</code></pre>

<pre><code>cloud_user@master-node:~$ k run nginx --image=nginx --restart=Never --limits=cpu=2,memory=2Gi
Error from server (Forbidden): pods "nginx" is forbidden: exceeded quota: compute-resources, requested: requests.cpu=2,requests.memory=2Gi, used: requests.cpu=0,requests.memory=0, limited: requests.cpu=1,requests.memory=1Gi
</code></pre>

<p>Here I'm adding yaml file for LimitRange, ResourceQuota</p>

<pre><code>apiVersion: v1
kind: LimitRange
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"LimitRange","metadata":{"annotations":{},"name":"default-limitrange","namespace":"default"},"spec":{"limits":[{"defaultRequest":{"cpu":"1","memory":"1Gi"},"type":"Container"}]}}
  creationTimestamp: "2020-03-28T08:05:40Z"
  name: default-limitrange
  namespace: default
  resourceVersion: "4966600"
  selfLink: /api/v1/namespaces/default/limitranges/default-limitrange
  uid: 3261f4d9-6339-478d-939c-395010b20aad
spec:
  limits:
  - default:
      cpu: "1"
      memory: 1Gi
    defaultRequest:
      cpu: "1"
      memory: 1Gi
    type: Container
</code></pre>

<pre><code>apiVersion: v1
kind: ResourceQuota
metadata:
  creationTimestamp: "2020-03-28T07:40:03Z"
  name: compute-resources
  namespace: default
  resourceVersion: "4967263"
  selfLink: /api/v1/namespaces/default/resourcequotas/compute-resources
  uid: 8a94a396-0774-4b62-8140-5a5f463935ed
spec:
  hard:
    limits.cpu: "2"
    limits.memory: 2Gi
    pods: "2"
    requests.cpu: "1"
    requests.memory: 1Gi
status:
  hard:
    limits.cpu: "2"
    limits.memory: 2Gi
    pods: "2"
    requests.cpu: "1"
    requests.memory: 1Gi
  used:
    limits.cpu: "0"
    limits.memory: "0"
    pods: "0"
    requests.cpu: "0"
    requests.memory: "0"
</code></pre>

Nandeesh
<p>This is documented <a href="https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/#what-if-you-specify-a-container-s-limit-but-not-its-request" rel="nofollow noreferrer">here</a>.If you specify a container’s limit, but not its request the container is not assigned the default memory request as per the limit range, rather the container’s memory request is set to match its memory limit specified while creating the pod. This is the reason why 
<code>requests.cpu=2,requests.memory=2Gi</code> is being set which matches with the limit specified while creating the pod.</p>
