Container resource defaults injection¶
Container resource defaults injection is a mechanism in Kubernetes that automatically applies default compute resource constraints to containers within a specific [[Namespace]] if they are not explicitly defined by the user^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. This process is handled by a resource policy known as a LimitRange^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].
In default Kubernetes configurations, running containers may operate without resource limits, potentially allowing a single workload to monopolize node resources^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. By defining a LimitRange, administrators can enforce constraints such as minimum and maximum CPU and memory usage per container or Pod^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. More importantly, the LimitRange object specifies default values for resource requests and limits (e.g., defaultRequest and default), which are injected into containers at runtime^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].
How it works¶
When a Pod is created in a namespace with a LimitRange, Kubernetes evaluates the container's resource specifications^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].
- Missing Resources: If a container does not declare its own CPU or memory requests/limits, the system automatically applies the values defined in the
LimitRange^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. For example, a container with no resource section in its manifest might be automatically assigned a request of500mCPU and a limit of1CPU upon creation^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. - Constraints Validation: The mechanism also ensures that any user-defined requests fall between the configured minimum and maximum values^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. If a container tries to start with a request lower than the defined minimum or a limit higher than the maximum, Kubernetes rejects the creation with a "Forbidden" error^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].
Related Concepts¶
- Kubernetes
- [[Namespace]]
- [[Resource Quota]]
- [[LimitRange]]
Sources¶
^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]