In shared Kubernetes clusters, multiple workloads compete for physical resources (CPU and Memory) on host Nodes. If resource constraints are not set, a single misconfigured or runaway application can consume all available memory or CPU on a Node, causing performance degradation or crashes of other workloads—a problem known as the Noisy Neighbor effect.
To prevent this, Kubernetes allows administrators and developers to define Resource Requests and Limits at the container level.
requests (Guaranteed Allocation):
requests configuration to select a suitable Node. The scheduler sums up the requests of all containers inside a Pod and places the Pod on a Node that has sufficient unallocated capacity. If no Node has enough free resource space, the Pod remains in the Pending state.limits (Maximum Threshold):
137.graph TD
Start([Pod Scheduled]) --> Schedule{Which Node has free Capacity >= Pod Requests?}
Schedule -->|None| Pending([Pod Pending Status])
Schedule -->|Node Found| Bind([Pod bound to Node])
Bind --> Run([Containers Running])
Run --> CheckCPU{Container CPU > Limit?}
CheckCPU -->|Yes| Throttle[Throttle CPU - App slows down]
CheckCPU -->|No| Safe1[App runs normally]
Run --> CheckMem{Container Memory > Limit?}
CheckMem -->|Yes| OOM[OOMKilled - Container terminated & restarted]
CheckMem -->|No| Safe2[App runs normally]
Kubernetes automatically assigns a QoS Class to each Pod based on how requests and limits are configured. The QoS class determines eviction priority if a Node runs out of resources:
Guaranteed (Highest Priority):
requests and limits are explicitly configured and are exactly equal for both CPU and Memory.Burstable (Medium Priority):
BestEffort (Lowest Priority):
thor (or active admin cluster terminal)defaulthttpd-podhttpd-containerhttpd:latest100m (0.1 core)15Mi100m20MiEstablish terminal access to the command host configured with cluster access:
ssh thor@jump_host_ip
Generate a base Pod manifest file using dry-run:
kubectl run httpd-pod \
--image=httpd:latest \
--restart=Never \
--dry-run=client \
-o yaml > httpd-pod.yaml
Edit the httpd-pod.yaml manifest:
vi httpd-pod.yaml
Update the spec.containers block to define container name, limits, and requests. Ensure they are placed under the container specifications:
apiVersion: v1
kind: Pod
metadata:
labels:
run: httpd-pod
name: httpd-pod
spec:
containers:
- name: httpd-container
image: httpd:latest
ports:
- containerPort: 80
resources:
requests:
memory: "15Mi"
cpu: "100m"
limits:
memory: "20Mi"
cpu: "100m"
restartPolicy: Never
Save and close the file (:wq).
Create the Pod in your cluster using the manifest:
kubectl apply -f httpd-pod.yaml
Inspect the container resource configurations directly from the cluster state:
kubectl get pod httpd-pod -o yaml
Locate the resources section inside the container specification block to verify the memory and CPU values match the configuration.
Check that the Pod was successfully categorized under the correct Quality of Service class:
kubectl describe pod httpd-pod | grep "QoS Class"
Expected Output:
QoS Class: Guaranteed
(Since requests and limits are configured and are exactly equal, the Pod receives the highest priority Guaranteed class).
Log out of the Application Server:
exit