Bird
Raised Fist0
Kubernetesdevops~10 mins

Resource requests and limits in Kubernetes - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a CPU request for a container in a pod spec.

Kubernetes
resources:
  requests:
    cpu: [1]
Drag options to blanks, or click blank then click option'
A2Gi
B500m
C1
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using memory units like '2Gi' for CPU request
Using plain numbers without units
2fill in blank
medium

Complete the code to set a memory limit for a container in a pod spec.

Kubernetes
resources:
  limits:
    memory: [1]
Drag options to blanks, or click blank then click option'
A1
B100m
C500m
D256Mi
Attempts:
3 left
💡 Hint
Common Mistakes
Using CPU units like '100m' for memory
Using plain numbers without units
3fill in blank
hard

Fix the error in the resource requests section by completing the blank.

Kubernetes
resources:
  requests:
    memory: [1]
Drag options to blanks, or click blank then click option'
A512Mi
B1000m
C1000
D512
Attempts:
3 left
💡 Hint
Common Mistakes
Using millicores units for memory
Omitting units for memory values
4fill in blank
hard

Fill both blanks to set CPU request and limit correctly.

Kubernetes
resources:
  requests:
    cpu: [1]
  limits:
    cpu: [2]
Drag options to blanks, or click blank then click option'
A250m
B500m
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Setting request higher than limit
Using memory units for CPU
5fill in blank
hard

Fill all three blanks to set memory request, memory limit, and CPU limit correctly.

Kubernetes
resources:
  requests:
    memory: [1]
  limits:
    memory: [2]
    cpu: [3]
Drag options to blanks, or click blank then click option'
A128Mi
B256Mi
C500m
D1Gi
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing CPU and memory units
Setting request higher than limit

Practice

(1/5)
1. What does setting a resource request for a container in Kubernetes guarantee?
easy
A. The container will get at least the requested CPU and memory resources.
B. The container can never use more than the requested resources.
C. The container will be restarted if it uses more than the requested resources.
D. The container will share resources equally with all other containers.

Solution

  1. Step 1: Understand resource requests in Kubernetes

    Resource requests specify the minimum CPU and memory a container needs to run properly.
  2. Step 2: Clarify what is guaranteed by requests

    Kubernetes ensures the container gets at least the requested resources but does not limit usage to that amount.
  3. Final Answer:

    The container will get at least the requested CPU and memory resources. -> Option A
  4. Quick Check:

    Resource request = minimum guaranteed resources [OK]
Hint: Requests guarantee minimum resources, limits cap maximum [OK]
Common Mistakes:
  • Confusing requests with limits
  • Thinking requests cap usage
  • Assuming requests cause restarts
2. Which of the following is the correct way to specify CPU and memory requests in a Kubernetes Pod YAML?
easy
A. resources: requests: cpu: "0.5" memory: "256MB"
B. resources: limits: cpu: 500 memory: 256
C. resources: requests: cpu: 500m memory: 256MiB
D. resources: requests: cpu: "500m" memory: "256Mi"

Solution

  1. Step 1: Review correct syntax for resource requests

    CPU requests use millicores with "m" suffix as string, memory uses Mi or Gi units as string.
  2. Step 2: Identify correct option

    resources: requests: cpu: "500m" memory: "256Mi" uses "500m" for CPU and "256Mi" for memory correctly as strings.
  3. Final Answer:

    resources: requests: cpu: "500m" memory: "256Mi" -> Option D
  4. Quick Check:

    CPU in millicores and memory in Mi with quotes [OK]
Hint: Use quotes and correct units like "500m" and "256Mi" [OK]
Common Mistakes:
  • Omitting quotes around resource values
  • Using wrong units like MB instead of Mi
  • Specifying CPU as plain number without m
3. Given this Pod spec snippet, what is the maximum CPU the container can use?
resources:
  requests:
    cpu: "200m"
  limits:
    cpu: "500m"
medium
A. 500 millicores
B. 200 millicores
C. 700 millicores
D. Unlimited CPU

Solution

  1. Step 1: Understand CPU requests and limits

    Requests set minimum guaranteed CPU, limits set maximum allowed CPU usage.
  2. Step 2: Identify maximum CPU from limits

    The limit is "500m", meaning 500 millicores is the max CPU the container can use.
  3. Final Answer:

    500 millicores -> Option A
  4. Quick Check:

    CPU limit = max CPU usage [OK]
Hint: Limits define max usage, requests define minimum [OK]
Common Mistakes:
  • Confusing requests with limits
  • Adding requests and limits incorrectly
  • Assuming no max limit if requests set
4. You set a memory limit of 256Mi but forgot to set a memory request. What is the likely effect on your Pod scheduling?
medium
A. The Pod will use unlimited memory since request is missing.
B. The Pod may be scheduled with no guaranteed memory, risking eviction under pressure.
C. The Pod will be scheduled with 256Mi guaranteed memory automatically.
D. The Pod will fail to start due to missing memory request.

Solution

  1. Step 1: Understand default behavior when requests are missing

    If memory request is not set, Kubernetes treats it as zero, meaning no guaranteed memory.
  2. Step 2: Effect on scheduling and eviction

    Pod may be scheduled but can be evicted if node memory is low because it has no guaranteed reservation.
  3. Final Answer:

    The Pod may be scheduled with no guaranteed memory, risking eviction under pressure. -> Option B
  4. Quick Check:

    Missing request means no guaranteed resources [OK]
Hint: Always set requests to guarantee resources and avoid eviction [OK]
Common Mistakes:
  • Assuming limits imply requests
  • Thinking Pod fails without requests
  • Believing missing requests mean unlimited resources
5. You want to ensure a container always has at least 100m CPU and 128Mi memory but never uses more than 300m CPU and 256Mi memory. Which is the correct resource configuration snippet?
hard
A. resources: requests: cpu: "300m" memory: "256Mi" limits: cpu: "100m" memory: "128Mi"
B. resources: limits: cpu: "100m" memory: "128Mi" requests: cpu: "300m" memory: "256Mi"
C. resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "300m" memory: "256Mi"
D. resources: requests: cpu: "100" memory: "128" limits: cpu: "300" memory: "256"

Solution

  1. Step 1: Match minimum guaranteed resources to requests

    Requests must be set to 100m CPU and 128Mi memory to guarantee minimum.
  2. Step 2: Match maximum allowed resources to limits

    Limits must be set to 300m CPU and 256Mi memory to cap usage.
  3. Step 3: Verify correct syntax and order

    resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "300m" memory: "256Mi" correctly sets requests first, then limits with proper units and quotes.
  4. Final Answer:

    resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "300m" memory: "256Mi" -> Option C
  5. Quick Check:

    Requests = min, Limits = max with correct units [OK]
Hint: Requests are min, limits are max; use correct units and quotes [OK]
Common Mistakes:
  • Swapping requests and limits
  • Omitting units or quotes
  • Using plain numbers without units
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard