Junior — Middle
What are the ways to configure limits and resources for containers in Kubernetes?
sobes.tech AI
Answer from AI
In Kubernetes, resource limits and requests for containers are configured using the resources.requests and resources.limits fields in Pod or container manifests.
- requests — the minimum amount of resources that the container is guaranteed to receive. The scheduler uses these values to select a node.
- limits — the maximum amount of resources that the container can use. If the limit is exceeded, the container may be restricted (e.g., CPU throttling) or restarted (e.g., when memory is exceeded).
Example of resource configuration in a Pod manifest:
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: example-container
image: nginx
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
You can also use LimitRange to set default constraints in a namespace and ResourceQuota to limit total resource consumption within a namespace.