Bird
Raised Fist0
Kubernetesdevops~20 mins

Resource quotas per namespace in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Resource Quota Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Check current resource quotas in a namespace
You run the command kubectl get resourcequota -n dev. What output do you expect if no resource quotas are set in the dev namespace?
Kubernetes
kubectl get resourcequota -n dev
A
NAME      AGE
cpu-quota  10d
BNo resources found in dev namespace.
CError from server (NotFound): resourcequotas "dev" not found
D
NAME      CPU    MEMORY
quota1    2      4Gi
Attempts:
2 left
💡 Hint
Think about what kubectl shows when no resource quotas exist in a namespace.
❓ Configuration
intermediate
2:00remaining
Define a resource quota limiting CPU and memory
Which YAML snippet correctly defines a resource quota named limit-quota in namespace test that limits CPU to 2 cores and memory to 4Gi?
A
apiVersion: v1
kind: ResourceQuota
metadata:
  name: limit-quota
  namespace: test
spec:
  hard:
    cpu: 2 cores
    memory: 4Gi
B
apiVersion: v1
kind: ResourceQuota
metadata:
  name: limit-quota
spec:
  hard:
    cpu: 2
    memory: 4Gi
  namespace: test
C
apiVersion: v1
kind: ResourceQuota
metadata:
  name: limit-quota
  namespace: test
spec:
  limits:
    cpu: "2"
    memory: 4Gi
D
apiVersion: v1
kind: ResourceQuota
metadata:
  name: limit-quota
  namespace: test
spec:
  hard:
    cpu: "2"
    memory: 4Gi
Attempts:
2 left
💡 Hint
Check the correct placement of namespace and the 'hard' field format.
❓ Troubleshoot
advanced
1:30remaining
Why is a pod creation failing due to resource quota?
You have a resource quota limiting pods to 5 in namespace prod. You try to create a 6th pod and get this error: pods "mypod" is forbidden: exceeded quota: pod-quota, requested: pods=1, used: pods=5, limited: pods=5. What is the root cause?
AThe namespace has reached the maximum allowed pods defined by the resource quota.
BThe pod spec requests more CPU than allowed by the quota.
CThe pod name conflicts with an existing pod in the namespace.
DThe resource quota is not applied to the namespace.
Attempts:
2 left
💡 Hint
Look at the error message details about pods and quota limits.
🔀 Workflow
advanced
2:00remaining
Steps to update an existing resource quota
You want to increase the CPU limit in an existing resource quota named cpu-quota in namespace dev from 2 to 4 cores. Which sequence of commands is correct?
A
kubectl get resourcequota cpu-quota -n dev -o yaml > quota.yaml
Edit quota.yaml to set cpu: "4"
kubectl apply -f quota.yaml -n dev
B
kubectl edit resourcequota cpu-quota -n dev
Change cpu to 4
Save and exit
CAll of the above sequences are correct
Dkubectl patch resourcequota cpu-quota -n dev --type='merge' -p '{"spec":{"hard":{"cpu":"4"}}}'
Attempts:
2 left
💡 Hint
Consider different ways kubectl allows editing resources.
✅ Best Practice
expert
1:30remaining
Why use resource quotas per namespace in a multi-team cluster?
What is the main benefit of applying resource quotas per namespace in a Kubernetes cluster shared by multiple teams?
AIt prevents any single team from using more than their fair share of cluster resources, ensuring fair resource distribution.
BIt automatically scales pods up and down based on team usage.
CIt encrypts all data stored in the namespace to secure team data.
DIt allows teams to bypass cluster-wide security policies.
Attempts:
2 left
💡 Hint
Think about resource fairness and limits in shared environments.

Practice

(1/5)
1. What is the main purpose of a ResourceQuota in a Kubernetes namespace?
easy
A. To limit the amount of resources like CPU and memory used in that namespace
B. To increase the CPU speed of all pods in the namespace
C. To delete unused pods automatically
D. To backup data stored in the namespace

Solution

  1. Step 1: Understand ResourceQuota purpose

    A ResourceQuota sets limits on resource usage like CPU, memory, pods, and storage within a namespace.
  2. Step 2: Compare options with purpose

    Only To limit the amount of resources like CPU and memory used in that namespace correctly describes limiting resource usage. Other options describe unrelated actions.
  3. Final Answer:

    To limit the amount of resources like CPU and memory used in that namespace -> Option A
  4. Quick Check:

    ResourceQuota limits resources = D [OK]
Hint: ResourceQuota controls resource limits per namespace [OK]
Common Mistakes:
  • Thinking ResourceQuota speeds up pods
  • Confusing quotas with backups
  • Assuming quotas delete pods automatically
2. Which of the following is the correct YAML snippet to define a CPU limit of 2 cores in a ResourceQuota?
easy
A. hard: limits.cpu: "2"
B. resources: limits: cpu: "2"
C. hard: cpu: "2"
D. hard: limits.cpu: 2

Solution

  1. Step 1: Recall ResourceQuota syntax for limits

    ResourceQuota uses the hard field with resource names like limits.cpu as keys and string values.
  2. Step 2: Check each option's syntax

    hard: limits.cpu: "2" correctly uses hard: with limits.cpu: "2". resources: limits: cpu: "2" uses wrong keys, C misses limits., D uses number instead of string.
  3. Final Answer:

    hard: limits.cpu: "2" -> Option A
  4. Quick Check:

    ResourceQuota hard limits use string values with resource keys [OK]
Hint: ResourceQuota limits use 'hard' with string values [OK]
Common Mistakes:
  • Using numeric values instead of strings
  • Omitting 'limits.' prefix in resource keys
  • Placing limits under wrong YAML keys
3. Given this ResourceQuota YAML applied to namespace dev:
apiVersion: v1
kind: ResourceQuota
metadata:
  name: dev-quota
  namespace: dev
spec:
  hard:
    pods: "3"
    requests.cpu: "1"
    requests.memory: "1Gi"
What happens if you try to create a 4th pod in dev namespace?
medium
A. The pod will be created normally without any error
B. The pod will be created but with limited CPU
C. The pod creation will fail due to exceeding the pod count quota
D. The pod will be created but memory will be limited to 1Gi

Solution

  1. Step 1: Understand pod count limit in ResourceQuota

    The quota limits pods to 3 in the dev namespace.
  2. Step 2: Effect of creating 4th pod

    Creating a 4th pod exceeds the pod count quota, so Kubernetes rejects the creation with an error.
  3. Final Answer:

    The pod creation will fail due to exceeding the pod count quota -> Option C
  4. Quick Check:

    Pod count quota exceeded = creation fails [OK]
Hint: Pod count quota blocks pods beyond limit [OK]
Common Mistakes:
  • Assuming pod is created with limited resources
  • Thinking quota only warns but allows creation
  • Confusing CPU/memory limits with pod count
4. You applied this ResourceQuota YAML but it fails to create:
apiVersion: v1
kind: ResourceQuota
metadata:
  name: test-quota
  namespace: test
spec:
  hard:
    cpu: "2"
    memory: "4Gi"
What is the likely error?
medium
A. Missing 'apiVersion' field
B. Namespace 'test' does not exist
C. Values should be numbers, not strings
D. Resource keys 'cpu' and 'memory' are invalid; should use 'limits.cpu' and 'limits.memory'

Solution

  1. Step 1: Check resource keys in ResourceQuota

    ResourceQuota requires full resource names like limits.cpu or requests.memory, not just cpu or memory.
  2. Step 2: Validate YAML fields

    API version is present, namespace existence is unrelated to syntax error, and values must be strings (which they are).
  3. Final Answer:

    Resource keys 'cpu' and 'memory' are invalid; should use 'limits.cpu' and 'limits.memory' -> Option D
  4. Quick Check:

    Use full resource keys like limits.cpu [OK]
Hint: Use full resource keys like limits.cpu in quotas [OK]
Common Mistakes:
  • Using short keys like 'cpu' instead of 'limits.cpu'
  • Assuming missing namespace causes syntax error
  • Using numeric values instead of strings
5. You want to limit a namespace to 5 pods and 2Gi memory requests, but allow unlimited CPU. Which ResourceQuota YAML snippet achieves this?
hard
A. spec: hard: pods: "5" requests.memory: "2Gi" requests.cpu: "0"
B. spec: hard: pods: "5" requests.memory: "2Gi"
C. spec: hard: pods: "5" requests.memory: "2Gi" limits.cpu: "unlimited"
D. spec: hard: pods: "5" requests.memory: "2Gi" requests.cpu: "-1"

Solution

  1. Step 1: Understand ResourceQuota limits

    To limit pods and memory requests, specify those keys under hard. Omitting CPU means no limit on CPU.
  2. Step 2: Evaluate options for CPU limits

    spec: hard: pods: "5" requests.memory: "2Gi" omits CPU limits, allowing unlimited CPU. Options A, C, D try to set CPU limits with invalid or restrictive values.
  3. Final Answer:

    spec: hard: pods: "5" requests.memory: "2Gi" -> Option B
  4. Quick Check:

    Omit CPU limit to allow unlimited CPU [OK]
Hint: Omit resource in quota to allow unlimited usage [OK]
Common Mistakes:
  • Setting CPU limit to 0 or negative disables pods
  • Using 'unlimited' as a value (not valid)
  • Trying to limit CPU when unlimited is desired
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