0
0
Kubernetesdevops~10 mins

Resource quotas per namespace in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Resource quotas per namespace
Create Namespace
Define ResourceQuota YAML
Apply ResourceQuota to Namespace
Kubernetes Enforces Limits
Pods/Resources Created Within Quota
Quota Usage Updated
Reject Excess Resource Requests
This flow shows how a resource quota is created and applied to a namespace, then Kubernetes enforces resource limits on pods and other objects within that namespace.
Execution Sample
Kubernetes
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
  namespace: dev
spec:
  hard:
    pods: "3"
    requests.cpu: "2"
    requests.memory: "4Gi"
This YAML defines a resource quota named 'compute-quota' in the 'dev' namespace limiting pods to 3, CPU requests to 2 cores, and memory requests to 4Gi.
Process Table
StepActionNamespace StateQuota UsageResult
1Create namespace 'dev'Namespace 'dev' created0 pods, 0 CPU, 0 MemoryNamespace ready
2Apply ResourceQuota 'compute-quota'Quota set: pods=3, CPU=2, Memory=4Gi0 pods, 0 CPU, 0 MemoryQuota active
3Create Pod1 requesting 1 CPU, 1Gi memoryPods=1CPU=1, Memory=1GiPod1 created
4Create Pod2 requesting 1 CPU, 2Gi memoryPods=2CPU=2, Memory=3GiPod2 created
5Create Pod3 requesting 1 CPU, 1Gi memoryPods=2CPU=2, Memory=3GiRejected: CPU quota exceeded
6Delete Pod1Pods=1CPU=1, Memory=2GiPod1 deleted, quota freed
7Create Pod3 requesting 1 CPU, 1Gi memoryPods=2CPU=2, Memory=3GiPod3 created
8Create Pod4 requesting 1 CPU, 3Gi memoryPods=2CPU=2, Memory=3GiRejected: Memory quota exceeded
9Create Pod4 requesting 1 CPU, 1Gi memoryPods=2CPU=2, Memory=3GiRejected: CPU quota exceeded
💡 Pods quota limit of 3 and CPU/memory limits enforced, excess requests rejected
Status Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 6After Step 7After Step 8After Step 9
Pods Count01221222
CPU Requests (cores)01221222
Memory Requests (Gi)01332333
Key Moments - 3 Insights
Why was Pod3 creation rejected at step 5 even though pods quota was not exceeded?
At step 5, CPU requests would exceed the quota of 2 cores (would become 3), so Kubernetes rejected Pod3. See execution_table row 5.
Why can Pod3 be created after deleting Pod1 at step 7?
Deleting Pod1 frees CPU and memory quota, so Pod3 fits within limits now. See execution_table rows 6 and 7.
Why was Pod4 rejected at step 9 despite requesting only 1 CPU and 1Gi memory?
CPU quota is 2 cores total. After step 7 (and 8), 2 CPU cores are in use by Pod2 and Pod3. Adding Pod4's 1 CPU exceeds it. See execution_table row 9.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the CPU requests usage after step 4?
A1 core
B2 cores
C3 cores
D0 cores
💡 Hint
Check the 'Quota Usage' column at step 4 in the execution_table.
At which step does the first pod rejection occur?
AStep 5
BStep 7
CStep 3
DStep 9
💡 Hint
Check the 'Result' column in the execution_table for the first 'Rejected'.
If Pod2 requested only 0.5 CPU instead of 1 CPU, what would happen at step 5?
APod3 creation would still be rejected
BPod2 creation would be rejected
CPod3 creation would succeed
DPods quota would be exceeded
💡 Hint
Consider CPU usage after step 4 and how it affects step 5 in execution_table.
Concept Snapshot
Resource Quotas limit resource use per namespace in Kubernetes.
Define a ResourceQuota YAML with 'hard' limits.
Apply it to a namespace to enforce limits on pods, CPU, memory.
Kubernetes rejects resource requests exceeding quota.
Quota usage updates dynamically as pods are created/deleted.
Full Transcript
Resource quotas in Kubernetes control how many resources like pods, CPU, and memory can be used in a namespace. First, you create a namespace, then define a ResourceQuota YAML specifying limits. When you apply this quota to the namespace, Kubernetes tracks resource usage. If you try to create pods or request resources beyond the quota, Kubernetes rejects those requests. Deleting pods frees quota, allowing new pods within limits. This ensures fair resource sharing and prevents one namespace from using too much.