https://drive.google.com/file/d/16snilNvcm5kKAWoRmJy0ub-xajEUTnIY/view?usp=sharing
apiVersion: v1
kind: Pod
meta
name: nnwebserver
spec:
containers:
- name: nnwebserver
image: nginx
resources:
requests: # β Minimum guaranteed resources
cpu: "500m" # = 0.5 CPU core
memory: "128Mi" # = 128 Mebibytes
limits: # β Maximum allowed resources
cpu: "1000m" # = 1.0 CPU core
memory: "256Mi" # = 256 Mebibytes
ports:
- containerPort: 80
name: http
protocol: TCP
requests vs limits| Term | Meaning | Used By | What Happens If Exceeded? |
|---|---|---|---|
requests |
Guaranteed minimum resources the container needs to start. | Kubernetes Scheduler β decides which node can run this Pod. | β
Never exceeded by scheduler β Pod wonβt be placed on a node without enough free requests. |
limits |
Hard ceiling β container cannot use more than this. | Kubelet + Container Runtime (e.g., containerd) | - CPU: Throttled (slowed down)<br>- Memory: OOMKilled (Pod crashes!) |
π‘ Units Explained:
500m= 500 milliCPU = 0.5 CPU core1000m= 1 full CPU core128Mi= 128 Mebibytes (1 MiB = 1024Β² bytes) β not 128 MB (1000Β²)
β Best Practice:
Always set both
requestsandlimitsin production.Without them, your Pod is BestEffort (lowest priority, first to be evicted!).
Scheduling:
Scheduler checks: "Does any node have β₯500m CPU and β₯128Mi free memory?"
β Only then places the Pod.
Runtime Enforcement:
QoS Class:
Because requests β limits (CPU: 500m β 1000m), this Pod is Burstable (medium priority).
π― Goal: Prevent one noisy app from starving others on the same node.
# Apply the Pod
kubectl apply -f pod-with-resource-limits.yml
# Check status
kubectl get pods
# Describe to see resources + QoS class
kubectl describe pod nnwebserver | grep -A 5 -B 2 "Limits\\\\|QoS"
β Expected Output:
Limits:
cpu: 1
memory: 256Mi
Requests:
cpu: 500m
memory: 128Mi
QoS Class: Burstable