
Introduction #
Discover ResourceQuotas and their role in Kubernetes.
What is a ResourceQuota? #
A ResourceQuota is a Kubernetes object that enforces limits on resource consumption in a namespace. It is used to control and manage the use of resources such as CPU, memory and storage volumes, as well as the number of objects such as Pods and Services.
Why use a ResourceQuota? #
ResourceQuotas let you:
- Prevent a single application from overconsuming resources.
- Ensure a fair distribution of resources.
- Optimize costs by limiting unused resources.
- Prevent incidents caused by excessive consumption.
How it works #
How ResourceQuotas work in Kubernetes.
Controlled resources #
ResourceQuotas can limit:
- CPU and memory (limits and requests).
- Persistent storage (PersistentVolumeClaims).
- The number of Kubernetes objects such as Pods, Services, ConfigMaps, etc.
Quota enforcement #
When a quota is defined in a namespace, Kubernetes monitors resource usage in real time. If a request exceeds the specified limits, it is rejected with an error message indicating which quota was exceeded.
Configuration example #
YAML configuration for a ResourceQuota.
Example YAML file #
apiVersion: v1
kind: ResourceQuota
metadata:
name: resource-quota-example
namespace: my-namespace
spec:
hard:
requests.cpu: "4"
requests.memory: "8Gi"
limits.cpu: "6"
limits.memory: "12Gi"
persistentvolumeclaims: "5"
pods: "20"
Field explanations #
The main fields include:
- requests.cpu and requests.memory: limits on requested resources.
- limits.cpu and limits.memory: limits on the maximum usable resources.
- persistentvolumeclaims: maximum number of PVCs in the namespace.
- pods: maximum number of Pods allowed.
Management and verification #
How to manage and check ResourceQuota usage.
Creating and applying #
To apply a ResourceQuota:
kubectl create namespace my-namespace
kubectl apply -f resource-quota.yamlChecking quotas #
To check the state of quotas in a namespace:
kubectl get resourcequota -n my-namespace
kubectl describe resourcequota resource-quota-example -n my-namespaceHandling overruns #
If a quota is exceeded, an error is displayed, for example:
Error from server (Forbidden): pods "example-pod" is forbidden: exceeded quota: resource-quota-example, requested: cpu=2, used: cpu=4, limited: cpu=6Best practices #
Tips for optimal use of ResourceQuotas.
Planning #
Assess application and team needs before defining quotas to avoid bottlenecks.
Monitoring #
Monitor resource usage with tools such as Prometheus or Grafana to anticipate necessary adjustments.
Combining with LimitRange #
Use LimitRange to define per-Pod or per-container limits alongside ResourceQuotas.
Conclusion #
Why ResourceQuotas matter.
ResourceQuotas are essential to ensure efficient and fair use of Kubernetes resources. They contribute to cluster stability and better cost management. Combined with monitoring tools and complementary policies, they help you optimize your Kubernetes deployments.