https://drive.google.com/file/d/16snilNvcm5kKAWoRmJy0ub-xajEUTnIY/view?usp=sharing

πŸ” YAML Breakdown

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


πŸ“Œ Core Concepts: 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:

βœ… Best Practice:

Always set both requests and limits in production.

Without them, your Pod is BestEffort (lowest priority, first to be evicted!).


πŸ” How Kubernetes Uses This

  1. Scheduling:

    Scheduler checks: "Does any node have β‰₯500m CPU and β‰₯128Mi free memory?"

    β†’ Only then places the Pod.

  2. Runtime Enforcement:

  3. 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.


πŸ§ͺ Lab: Deploy & Observe Resource Behavior

πŸ”§ Part 1: Deploy the Pod

# 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