Hi Team, what’s the difference betwen the max and default limit in the Limit range ? Thanks !
Is the default limit value used by scheduler for scheduling the pod ? Which values are used by the scheduler for scheduling the pod ?
The example in the lecture is taken from the documentation here.
Let’s test it
-
Create a pod with nothing set for the resources section
apiVersion: v1 kind: Pod metadata: name: example-conflict-with-limitrange-cpu spec: containers: - name: demo image: registry.k8s.io/pause:2.0Read it back with
k get pod example-conflict-with-limitrange-cpu -o yamland see that it has been created with the default limit and request…apiVersion: v1 kind: Pod metadata: name: example-conflict-with-limitrange-cpu namespace: default spec: containers: - image: registry.k8s.io/pause:2.0 name: demo resources: limits: cpu: 500m # <- set by limits.default requests: cpu: 500m # <- set by limits.defaultRequest` -
If you create the pod with
requests.cpubut no value forlimits.cpuas on the documentation page, the request will fail as it is necessary to specify limits. -
If you create the pod with only
limits.cpuand the limit is valid (withinminandmax), thenrequests.cpuwill be set to the same value you gave forlimits.cpuapiVersion: v1 kind: Pod metadata: name: example-conflict-with-limitrange-cpu spec: containers: - name: demo image: registry.k8s.io/pause:2.0 resources: limits: cpu: 700mRead it back with
k get pod example-conflict-with-limitrange-cpu -o yamland see that it has been created with your value for limit and request set to the same…apiVersion: v1 kind: Pod metadata: name: example-conflict-with-limitrange-cpu namespace: default spec: containers: - image: registry.k8s.io/pause:2.0 name: demo resources: limits: cpu: 700m # <- set by you requests: cpu: 700m # <- set by LimitRage to the same value as limits.cpu
Thanks for the response but my following questions are still unanswered.
- What’s the difference betwen the max and default limit in the Limit range ?
- Which values are used by the scheduler for scheduling the pod?
-
maxis the maximum you are allowed to set without getting an error when you try to create the pod, anddefaultis the value that will be set if you do not putresourcesin the pod. - None of them.
LimitRangeis used by an admission controller. The admission controller validates any values forresourcesyou have set, and adds any values you have not set and then writes the adjusted pod manifest to etcd, that is, it sees the adjusted manifests above - the ones I commented. Only then does the scheduler see it at which point it is scheduled in the normal way using the final values forresources
