Bird
Raised Fist0
Kubernetesdevops~20 mins

Resource requests and limits in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Resource Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Pod resource requests and limits effect on scheduling
Given the following Pod YAML, what will be the status of the Pod after applying it to a cluster with only 500m CPU available on any node?

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: app
    image: nginx
    resources:
      requests:
        cpu: "600m"
      limits:
        cpu: "1"
Kubernetes
kubectl apply -f pod.yaml
kubectl get pod test-pod -o jsonpath='{.status.phase}'
APending
BRunning
CCrashLoopBackOff
DSucceeded
Attempts:
2 left
💡 Hint
Think about how Kubernetes schedules Pods based on resource requests.
🧠 Conceptual
intermediate
1:30remaining
Understanding resource limits impact on container behavior
What happens if a container tries to use more CPU than its limit in Kubernetes?
AThe container is throttled and CPU usage is limited to the set limit
BThe container is immediately terminated
CThe container ignores the limit and uses more CPU
DThe Pod is evicted from the node
Attempts:
2 left
💡 Hint
Think about how CPU limits control usage but do not kill the container.
❓ Troubleshoot
advanced
2:30remaining
Diagnosing OOMKilled due to memory limits
A Pod is repeatedly restarting with status 'OOMKilled'. The Pod spec includes:

resources:
  limits:
    memory: "256Mi"
  requests:
    memory: "128Mi"

What is the most likely cause?
AThe container image is corrupted causing crashes
BThe container did not request enough CPU and was throttled
CThe container tried to use more than 256Mi memory and was killed by the system
DThe Pod was evicted due to node disk pressure
Attempts:
2 left
💡 Hint
OOMKilled means out of memory kill by the kernel.
🔀 Workflow
advanced
2:00remaining
Setting resource requests and limits in a Deployment YAML
Which snippet correctly sets CPU requests to 200m and limits to 500m for a container in a Deployment?
A
resources:
  requests:
    memory: "200m"
  limits:
    memory: "500m"
B
resources:
  limits:
    cpu: "200m"
  requests:
    cpu: "500m"
C
resources:
  cpu:
    requests: "200m"
    limits: "500m"
D
resources:
  requests:
    cpu: "200m"
  limits:
    cpu: "500m"
Attempts:
2 left
💡 Hint
Remember the correct keys under resources are requests and limits.
✅ Best Practice
expert
3:00remaining
Choosing resource requests and limits for production workloads
Which approach is best when setting resource requests and limits for a production Kubernetes workload?
ASet requests low and limits very high to allow burst usage without scheduling issues
BSet requests based on average usage and limits slightly above to allow bursts, monitoring and adjusting over time
CSet requests and limits equal to the maximum expected usage to avoid throttling and evictions
DDo not set requests or limits to let Kubernetes manage resources automatically
Attempts:
2 left
💡 Hint
Think about balancing resource guarantees and flexibility.

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