Difference between max and default limit in Limit range

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

  1. 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.0
    

    Read it back with k get pod example-conflict-with-limitrange-cpu -o yaml and 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`
    
  2. If you create the pod with requests.cpu but no value for limits.cpu as on the documentation page, the request will fail as it is necessary to specify limits.

  3. If you create the pod with only limits.cpu and the limit is valid (within min and max), then requests.cpu will be set to the same value you gave for limits.cpu

    apiVersion: v1
    kind: Pod
    metadata:
      name: example-conflict-with-limitrange-cpu
    spec:
      containers:
      - name: demo
        image: registry.k8s.io/pause:2.0
        resources:
          limits:
            cpu: 700m
    

    Read it back with k get pod example-conflict-with-limitrange-cpu -o yaml and 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?
  • max is the maximum you are allowed to set without getting an error when you try to create the pod, and default is the value that will be set if you do not put resources in the pod.
  • None of them. LimitRange is used by an admission controller. The admission controller validates any values for resources you 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 for resources