Enforce Resource Policies Using LimitRange
Scenario
A namespace project-x already exists in the cluster. The platform team wants to enforce resource policies for all containers running in this namespace.
Task
- Create a LimitRange named
projectx-limitsin theproject-xnamespace that applies to containers only with the following rules:- Minimum CPU request:
100m, Minimum Memory request:128Mi - Maximum CPU limit:
800m, Maximum Memory limit:1Gi - If developers do not specify resources, the following defaults will be applied automatically:
Resource Default Request Default Limit CPU 200m500mMemory 256Mi512Mi
- Minimum CPU request:
- Ensure the LimitRange applies to containers only.
- Create a Pod named
ml-workerusing the imagenginxin the same namespace. - Ensure the Pod's resource configuration does not exceed the default request and default limit values defined in the LimitRange.
- Verify that the Pod is successfully created and complies with the LimitRange policies.
Hint 1
A LimitRange uses min, max, default, and defaultRequest fields under spec.limits. Set type: Container to apply rules to containers only. See the official docs: LimitRange