Day-39: Resource Quota in Kubernetes

Greetings! 👋 I'm Priyadarshi Ranjan, a dedicated DevOps Engineer embarking on an enriching journey. Join me as I delve into the dynamic realms of cloud computing and DevOps through insightful blogs and updates. 🛠️ My focus? Harnessing AWS services, optimizing CI/CD pipelines, and mastering infrastructure as code. Whether you're peers, interns, or curious learners, let's thrive together in the vibrant DevOps ecosystem. 🌐 Connect with me for engaging discussions, shared insights, and mutual growth opportunities. Let's embrace the learning curve and excel in the dynamic realm of AWS and DevOps technology!
Introduction
In Kubernetes, managing resources efficiently is crucial, especially in a multi-tenant environment. Here, Resource Quotas play a vital role. But what exactly is a Resource Quota, and how does it function?
Kubernetes में, resources को efficiently manage करना बहुत जरूरी होता है, खासकर जब आप multi-tenant environment में काम कर रहे हों। यहाँ पर Resource Quotas का एक अहम रोल होता है। लेकिन ये Resource Quota आखिर है क्या, और इसका काम क्या है?
What is a Resource Quota?

A Resource Quota in Kubernetes is a way to limit the resource usage per namespace. It ensures that no single team or application can consume more than their fair share of resources in a shared environment.
Kubernetes में, Resource Quota एक ऐसा तरीका है जिससे आप एक namespace के अंदर resource usage को limit कर सकते हैं। इसका मतलब है कि कोई भी team या application shared environment में जितना resources उन्हें allocate किया गया है, उससे ज्यादा use नहीं कर सकते।
Example: Imagine you have a server with limited CPU and memory. If one team starts using more than their share, it could affect other teams. Resource Quotas prevent this by setting limits.
Components of a Resource Quota
Pods: Limits the number of pods that can be created.
CPU: Limits the amount of CPU that can be used.
Memory: Limits the amount of memory that can be used.
PersistentVolumeClaims: Limits the number of Persistent Volume Claims (PVCs) that can be created.
Services: Limits the number of services that can be created.
Each of these components helps in managing and controlling the resource usage within a namespace, ensuring fair resource allocation.
Pods: ये limit करता है कि कितने pods create किए जा सकते हैं।
CPU: ये limit करता है कि कितना CPU use किया जा सकता है।
Memory: ये limit करता है कि कितनी memory use की जा सकती है।
PersistentVolumeClaims: ये limit करता है कि कितने Persistent Volume Claims (PVCs) create किए जा सकते हैं।
Services: ये limit करता है कि कितनी services create की जा सकती हैं।
ये सभी components मिलकर namespace के अंदर resource usage को manage और control करने में मदद करते हैं, जिससे कि सभी को बराबर resource मिले।
Example 1: Object Count Quota
Let's create a resource quota for limiting the number of pods in a namespace.
Step 1: Create Namespace sit
kubectl create ns sit
Step 2: Write a Manifest File object-count-quota.yml
apiVersion: v1
kind: ResourceQuota
metadata:
name: pod-count-quota
namespace: sit
spec:
hard:
pods: "2"
This manifest limits the namespace sit to only 2 pods.
Step 3: Apply the Quota and Test
kubectl apply -f object-count-quota.yml
kubectl get quota -n sit
Now, let's create two pods using pod2.yml.
kubectl apply -f pod2.yml
kubectl get pods -n sit
To check if the quota is enforced, try creating a third pod with pod3.yml.
kubectl apply -f pod3.yml
kubectl get pods -n sit
You should see an error indicating that the quota has been exceeded.
Example 2: Compute Resource Quota
Now let's set up a resource quota for CPU and memory in the uat namespace.
Step 1: Create Namespace uat
kubectl create ns uat
Step 2: Write a Manifest File compute-resource-quota.yml
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-resource-quota
namespace: uat
spec:
hard:
requests.cpu: "2"
requests.memory: "1Gi"
limits.cpu: "4"
limits.memory: "2Gi"
This manifest limits the CPU and memory usage in the uat namespace.
Step 3: Dry Run and Apply the Quota
First, check if the manifest is valid using a dry run:
kubectl apply -f compute-resource-quota.yml --dry-run=client
If valid, apply the quota:
kubectl apply -f compute-resource-quota.yml
Conclusion
Resource Quotas are essential for managing resources in a shared Kubernetes environment. They ensure that all teams and applications get a fair share of the resources, preventing any single entity from consuming more than its share.
Resource Quotas Kubernetes के shared environment में resources को manage करने के लिए बेहद जरूरी हैं। ये सुनिश्चित करते हैं कि सभी teams और applications को बराबर resources मिलें, और कोई भी एक entity अपनी quota से ज्यादा resources न use कर सके।
Connect and Follow Me on Socials




