π Set Resource Limits in Kubernetes Pods

I am Bittu Sharma, a DevOps & AI Engineer with a keen interest in building intelligent, automated systems. My goal is to bridge the gap between software engineering and data science, ensuring scalable deployments and efficient model operations in production.! ππ²π'π ππΌπ»π»π²π°π I would love the opportunity to connect and contribute. Feel free to DM me on LinkedIn itself or reach out to me at bittush9534@gmail.com. I look forward to connecting and networking with people in this exciting Tech World.
Resource management is one of the most important aspects of running applications in Kubernetes. By setting CPU and memory requests and limits, you ensure fair resource usage and prevent a single Pod from consuming all node resources.
In this guide, weβll create an Apache HTTPD Pod with defined CPU and memory requests and limits.
π§ Task Overview
We need to create a Kubernetes Pod with the following specifications:
| Configuration | Value |
| Pod Name | httpd-pod |
| Container Name | httpd-container |
| Image | httpd:latest |
| CPU Request | 100m |
| Memory Request | 15Mi |
| CPU Limit | 100m |
| Memory Limit | 20Mi |
βΉοΈ Note:
kubectlis already configured to interact with the Kubernetes cluster.
π Why Resource Requests and Limits Matter
Requests define the minimum resources guaranteed to a Pod
Limits define the maximum resources a Pod can consume
Prevents resource starvation
Improves cluster stability and performance
π§© Step 1: Create the Pod YAML File
Create a file named httpd-pod.yaml.
π Create the file
vi httpd-pod.yaml
π Pod Definition
apiVersion: v1
kind: Pod
metadata:
name: httpd-pod
spec:
containers:
- name: httpd-container
image: httpd:latest
resources:
requests:
memory: "15Mi"
cpu: "100m"
limits:
memory: "20Mi"
cpu: "100m"
π YAML Explanation
resources:
requests:
memory: "15Mi" # Minimum memory guaranteed
cpu: "100m" # Minimum CPU guaranteed (0.1 core)
limits:
memory: "20Mi" # Maximum memory allowed
cpu: "100m" # Maximum CPU allowed
Mi= Mebibytes100mCPU = 0.1 CPU core
π Step 2: Apply the Pod Configuration
Deploy the Pod to the Kubernetes cluster:
kubectl apply -f httpd-pod.yaml
β Expected Output
pod/httpd-pod created
π Step 3: Verify the Pod
Check the Pod status:
kubectl get pod httpd-pod
π’ Sample Output
NAME READY STATUS RESTARTS AGE
httpd-pod 1/1 Running 0 20s
π§Ύ Step 4: Verify Resource Limits
Describe the Pod and inspect resource limits:
kubectl describe pod httpd-pod | grep -A5 "Limits"
π’ Sample Output
Limits:
cpu: 100m
memory: 20Mi
Requests:
cpu: 100m
memory: 15Mi
π οΈ Common Troubleshooting Tips
β Pod stuck in Pending
kubectl describe pod httpd-pod
βοΈ Node may not have sufficient resources
βοΈ Requests exceed available capacity
β Pod gets OOMKilled
βοΈ Increase memory limit
βοΈ Optimize application memory usage
π― Conclusion
In this guide, you learned how to:
Define CPU and memory requests
Set resource limits for a Kubernetes Pod
Deploy and verify a resource-constrained Pod
Inspect Pod resource configurations
Setting resource limits is a best practice in production Kubernetes clusters to ensure reliability and fair scheduling.
π Next Steps
Here are some excellent follow-up topics:
Resource Quotas per Namespace
LimitRange in Kubernetes
Horizontal Pod Autoscaler (HPA)
Monitoring resource usage with metrics-server




