Skip to content

Kubernetes default resource injection

Kubernetes default resource injection is a mechanism that automatically applies CPU and memory 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 functionality is primarily implemented through the LimitRange resource.^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md] By defining a LimitRange, administrators can enforce policies that manage compute resources efficiently and prevent individual containers from monopolizing node resources.^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md]

How it works

When a LimitRange is created in a namespace, it specifies constraints such as default (for the Limit) and defaultRequest (for the Request).^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md] If a Pod is created without specifying resource requests or limits for its containers, Kubernetes automatically injects these default values defined in the LimitRange at runtime.^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md]

For example, if a container is deployed with an empty resources block, the cluster will assign the values from the LimitRange configuration to that container.^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md]

Constraints and Enforcement

While the mechanism injects defaults, it also enforces boundaries to ensure stability and compliance:

  • Minimum Constraint: The system ensures that every container declares a request value that is at least equal to the defaultRequest (minimum) defined in the LimitRange.^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md] If a user tries to create a Pod with a request lower than this minimum, creation is forbidden^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md].
  • Maximum Constraint: The system ensures that limits do not exceed the defined maximum.^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md] Attempting to create a Pod with a limit higher than allowed results in a forbidden error^[400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md].

Sources

  • 400-devops__06-Kubernetes__k8s-ithelp__Day23__README.md