How to set resource limits on AI agent pods

Set a CPU and a memory request and limit on every container in an AI agent pod. The scheduler uses the requests to place the pod, and the kubelet enforces the limits. CPU over its limit is throttled. Memory over its limit can get the container killed under memory pressure.
Checked against the Kubernetes concepts documentation as fetched on 2026-11-17.
What requests and limits do for an agent pod
Each resource has two numbers. The request is what the kube-scheduler reads when it decides which node the pod runs on. The limit is what the kubelet enforces on the running container, so the container cannot use more than the limit. The kubelet also reserves at least the request for that container.
A container can use more than its request when the node has spare capacity. The docs give an example: a 256 MiB memory request on an 8 GiB node with no other pods lets the container try to use more RAM. The request is a floor for scheduling, and the limit is the ceiling at runtime. An agent that is idle most of the time can therefore run well above its request on a quiet node.
Set requests and limits on the agent container
- Add a
resourcesblock to each container underspec.containers[]. Setrequestsandlimitsfor bothcpuandmemory. The docs list these four field paths:requests.cpu,requests.memory,limits.cpuandlimits.memory. - Write CPU as cores or millicores. The docs say
0.1and100mare the same amount, and that Kubernetes does not accept a precision finer than1m. - Write memory with a suffix such as
MiorGi. The docs note thatMmeans megabytes andmmeans millibytes, so400masks for 0.4 bytes. Write400Mifor 400 mebibytes. - Apply the same rules to every container in the pod, including sidecars. The Kyverno policy later in this post checks init containers too.
apiVersion: v1
kind: Pod
metadata:
name: agent
spec:
containers:
- name: agent
image: images.my-company.example/agent:v1
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
The shape follows the container example in the Kubernetes docs. The numbers are illustrative, so size them from the agent’s own usage. This pod has requests lower than its limits, which places it in the Burstable class described next.
Choose a QoS class on purpose
Kubernetes gives every pod a Quality of Service class based on its requests and limits. The class sets the order of eviction when a node runs short of resources. The table compares the three classes as the pod QoS page defines them.
| QoS class | What the docs require | Evicted under node pressure |
|---|---|---|
Guaranteed |
Every container has a CPU and a memory request and limit, each greater than zero, and each request equals its limit | Last |
Burstable |
The pod is not Guaranteed, and at least one container has a CPU or memory request or limit | After all BestEffort pods |
BestEffort |
No container has a CPU or memory request or limit | First |
The docs say that under node resource pressure, “only Pods exceeding resource requests are candidates for eviction.” An agent pod that stays within its requests is less exposed than one that runs past them. To reach Guaranteed, set each request equal to its limit. Guaranteed pods “may not acquire resources beyond their specified limits,” so that choice trades burst room for predictability.
How a runaway agent hits each limit
Two behaviours matter for an agent that loops or leaks memory.
CPU limits are a hard ceiling, enforced by throttling: “Containers may not use more CPU than is specified in their cpu limit.” A runaway loop slows down but keeps running. The limit protects the other pods on the node, but it does not stop the agent’s process.
Memory limits are enforced later, and by the kernel. The docs say a container “may use more memory than its memory limit, but if it does, it may get killed.” They also say “terminations only happen when the kernel detects memory pressure.” A memory leak can therefore run past its limit until the kernel acts. The docs do not define that pressure, and a container can be killed for exceeding its own limit without the node being short of memory, so test the agent’s behavior at its limit instead of assuming node-wide pressure. Expect the kill when it comes, and design the agent so a restart does not lose work it cannot redo. That kill is the kernel’s OOM kill of one container. It is separate from the kubelet’s eviction of whole pods under node pressure, which the QoS section above covers.
Fine print that changes the outcome
- A limit with no request is copied. If you set a limit and no request, Kubernetes uses the limit as the request, unless an admission-time mechanism has applied a default. The scheduler then reserves the full limit on the node.
- A missing limit is the node’s capacity. The Burstable definition says that if a limit is not specified, “it defaults to a limit equivalent to the capacity of the Node.” An agent container with a request and no limit can grow until it takes the whole node.
- No requests means first to go. A pod with no CPU or memory request or limit is BestEffort, and the kubelet evicts those pods first under pressure.
- Units are case-sensitive. The docs warn that
mandMare different suffixes, so review every memory value in the manifest, including the ones you did not change.
Enforcing this with Kyverno
Kyverno’s policy library has a policy named require-requests-limits, with the page at require-pod-requests-limits. It requires every regular and init container to set a CPU request, a memory request and a memory limit. Its minimum Kyverno version is 1.19.1. It sets validationActions to Audit, so check that mode against your rollout before you rely on it to block anything.
Use the policy to find agent pods that skip these settings, and keep the manifest rules above in the agent’s own chart. The Kyverno open source project page covers the engine that runs the policy. For governance of agents across clusters, see governing AI agents and the AI agent governance page. For the security settings that sit alongside these limits, read the Pod Security Admission levels for AI agent workloads and how to sandbox AI agents on Kubernetes.
Sources
- Kubernetes: Resource Management for Pods and Containers
- Kubernetes: Pod Quality of Service Classes
- Kyverno policy library: Require Requests and Limits
Frequently asked questions
Should an AI agent pod set a CPU limit?
Yes, if you want a ceiling on what the agent can take from the node. The Kubernetes docs say the kubelet enforces CPU limits by throttling. A container that reaches its CPU limit is held to that amount, and it is not killed. A CPU limit therefore slows a looping agent down instead of stopping it. Pair the limit with a CPU request so the scheduler reserves capacity for the pod.
Will a memory limit stop an agent that leaks memory?
Not at the moment it crosses the limit. The docs say the kernel terminates a container over its memory limit only when it detects memory pressure, a condition they do not define, so the container may run above the limit for a time. Treat the memory limit as a ceiling that the kernel enforces under pressure, and make the agent restartable, because a kill is a normal outcome.
What is the difference between a request and a limit?
The scheduler uses the request to choose a node for the pod. The kubelet enforces the limit on the running container. A container can use more than its request when the node has spare capacity, up to its limit. If you set a limit and no request, Kubernetes copies the limit into the request, unless an admission-time mechanism has set a default request.
Which QoS class should an agent pod get?
Guaranteed requires every container to set a CPU and a memory request equal to its limit, with both above zero. Burstable applies when at least one container sets a CPU or memory request or limit and the pod is not Guaranteed. BestEffort applies when no container sets either. Under node pressure, BestEffort pods are evicted first, then Burstable, then Guaranteed.
Does the Kyverno require-requests-limits policy check CPU limits?
No. The policy requires every regular and init container to set CPU and memory requests and a memory limit. It does not check for a CPU limit, so a container with a CPU request and no CPU limit passes. The policy also skips ephemeral containers, because Kubernetes does not support requests or limits for them, and it skips any image listed in its allowed images exception.