Bird
0
0

Which LimitRange YAML snippet correctly enforces this?

hard📝 Best Practice Q15 of 15
Kubernetes - Namespaces
You want all containers in a namespace to have a default CPU request of 200m and a default memory request of 512Mi, but also want to ensure no container can request more than 1 CPU or 1Gi memory. Which LimitRange YAML snippet correctly enforces this?
AapiVersion: v1\nkind: LimitRange\nmetadata:\n name: resource-limits\nspec:\n limits:\n - default:\n cpu: 200m\n memory: 512Mi\n max:\n cpu: 1\n memory: 1Gi\n type: Container
BapiVersion: v1\nkind: LimitRange\nmetadata:\n name: resource-limits\nspec:\n limits:\n - defaultRequest:\n cpu: 200m\n memory: 512Mi\n maxLimit:\n cpu: 1\n memory: 1Gi\n type: Container
CapiVersion: v1\nkind: LimitRange\nmetadata:\n name: resource-limits\nspec:\n limits:\n - defaultCpu:\n cpu: 200m\n memory: 512Mi\n maxCpu:\n cpu: 1\n memory: 1Gi\n type: Container
DapiVersion: v1\nkind: LimitRange\nmetadata:\n name: resource-limits\nspec:\n limits:\n - default:\n cpu: 200m\n memory: 512Mi\n maxRequest:\n cpu: 1\n memory: 1Gi\n type: Container
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct keys for defaults and max

    The correct keys are default for default requests and max for maximum allowed resources under limits.
  2. Step 2: Validate YAML structure

    apiVersion: v1\nkind: LimitRange\nmetadata:\n name: resource-limits\nspec:\n limits:\n - default:\n cpu: 200m\n memory: 512Mi\n max:\n cpu: 1\n memory: 1Gi\n type: Container correctly uses default and max keys with proper resource names and type: Container.
  3. Step 3: Check other options for invalid keys

    Options B, C, and D use invalid keys like defaultRequest, maxLimit, defaultCpu, or maxRequest which are not valid in LimitRange spec.
  4. Final Answer:

    Option A correctly enforces default and max resource limits -> Option A
  5. Quick Check:

    Use 'default' and 'max' keys for defaults and max limits [OK]
Quick Trick: Use 'default' and 'max' keys under limits for defaults and max limits [OK]
Common Mistakes:
  • Using invalid keys like defaultRequest or maxLimit
  • Mixing up default and max keys
  • Incorrect YAML indentation or structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes