Memorize this block

CKA Practice Lab 157 - Resource Quota and Limit Range

Objective

Create a namespace named limited configured so that:


Important Exam Concept

There are two different places where memory requests appear in Kubernetes:

Pod/Deployment Specification

This answers:

What does this individual pod want?
resources:
  requests:
    memory: 32Mi

ResourceQuota

This answers:

How much can the entire namespace consume?
spec:
  hard:
    requests.memory: 1Gi
Memory Trick:
Pod specs use nested fields: resources.requests.memory

ResourceQuota uses flattened keys: requests.memory

Step 1 - Create Namespace

kubectl create ns limited

Step 2 - Create ResourceQuota

Create quota.yaml:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: quota
  namespace: limited
spec:
  hard:
    pods: "5"
    requests.memory: 1Gi

Apply it:

kubectl apply -f quota.yaml

Step 3 - Create LimitRange

To enforce that every container requests at least 32Mi memory.

Create limitrange.yaml:

apiVersion: v1
kind: LimitRange
metadata:
  name: mem-limit
  namespace: limited
spec:
  limits:
  - type: Container
    min:
      memory: 32Mi

Apply it:

kubectl apply -f limitrange.yaml

Step 4 - Create Deployment

Create deploy.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: lab157deploy
  namespace: limited
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: nginx
        image: nginx
        resources:
          requests:
            memory: 32Mi

Apply it:

kubectl apply -f deploy.yaml

Verification Commands

Verify Quota

kubectl get resourcequota -n limited
kubectl describe resourcequota quota -n limited

Verify LimitRange

kubectl get limitrange -n limited
kubectl describe limitrange mem-limit -n limited

Verify Deployment

kubectl get deploy,pods -n limited

Useful kubectl explain Commands

If you forget the YAML during the exam:

kubectl explain resourcequota.spec.hard

This often reminds you of:

pods
requests.cpu
requests.memory
limits.cpu
limits.memory

For LimitRange:

kubectl explain limitrange.spec.limits

High Value CKA Fields to Memorize

pods:
requests.cpu:
requests.memory:
limits.cpu:
limits.memory:

These are by far the most commonly used ResourceQuota fields encountered in CKA troubleshooting and configuration tasks.