Yes, LimitRange can set default values for resource requests and limits in Kubernetes. When a LimitRange is defined in a namespace, it can specify default values for CPU and memory resources. If a pod is created without explicitly defining resource requests or limits, Kubernetes will automatically apply these default values from the LimitRange.
Here’s an example of how to define a LimitRange with default values:
apiVersion: v1
kind: LimitRange
metadata:
name: example-limit-range
namespace: example-namespace
spec:
limits:
- default:
cpu: "500m"
memory: "256Mi"
defaultRequest:
cpu: "250m"
memory: "128Mi"
type: Container
In this example:
- The
defaultfield specifies the default limits for CPU and memory. - The
defaultRequestfield specifies the default requests for CPU and memory.
When a pod is created in the example-namespace without resource specifications, it will automatically receive the defined default values for CPU and memory.
