Tell the scheduler what each pod needs with requests, cap what it can take with limits, organize workloads into namespaces, and enforce fair sharing with ResourceQuotas.
Why: these two numbers govern scheduling and stability. A request is what a container is guaranteed — the scheduler only places a pod on a node with that much free. A limit is the ceiling it may never exceed. Exceed the CPU limit and you are throttled; exceed the memory limit and the container is killed (OOMKilled). Set both, deliberately.
spec:
containers:
- name: app
image: myapp:1.0
resources:
requests: # guaranteed, used for scheduling
cpu: "250m" # 250 millicores = 1/4 of a core
memory: "256Mi"
limits: # hard ceiling
cpu: "500m"
memory: "512Mi"A namespace is a virtual cluster inside your cluster — a way to group and isolate workloads by team, environment, or app. Names only need to be unique within a namespace, and you can apply quotas and access rules per namespace. -n targets one; most kubectl commands take it.
Create a namespace
kubectl create namespace stagingDeploy into it, and list only its pods
kubectl apply -f web.yaml -n stagingkubectl get pods -n stagingWhy: without limits, one team's runaway workload can starve a shared cluster. A ResourceQuota caps the total a namespace may request and use — combined CPU, memory, and object counts. Once set, the cluster rejects any pod that would push the namespace over budget.
apiVersion: v1
kind: ResourceQuota
metadata:
name: team-quota
namespace: staging
spec:
hard:
requests.cpu: "4"
requests.memory: 8Gi
limits.cpu: "8"
limits.memory: 16Gi
pods: "20"Why: a ResourceQuota that requires every pod to declare requests will reject pods that forget to. A LimitRange supplies default requests and limits for any container that omits them, so a quota-enforced namespace stays usable without every author remembering the boilerplate.
apiVersion: v1
kind: LimitRange
metadata:
name: defaults
namespace: staging
spec:
limits:
- type: Container
default: # applied as the limit if unset
cpu: "500m"
memory: 512Mi
defaultRequest: # applied as the request if unset
cpu: "250m"
memory: 256Mi