The following LimitRange configuration contains a negative resource request:
apiVersion: v1
kind: LimitRange
metadata:
name: negative-constraint
spec:
limits:
- defaultRequest:
cpu: '-150m'
type: Container
The API server allows me to create the LimitRange object. However, when I create a Pod in the same namespace, the API server rejects the request.
$ kubectl run nginx --image=nginx
The Pod "nginx" is invalid: spec.containers[0].resources.requests[cpu]: Invalid value: "-150m": must be greater than or equal to 0
Is there ever a scenario when negative resource requests or limits are valid? Why doesn’t the API server reject this?
Interestingly, if I attempt to create a ResourceQuota with a negative value for a resource in the spec, I do get an error from the API server saying the value must be greater than or equal to 0.