Running an AI agent in a development environment is relatively straightforward. Running one continuously in production is a different problem.
A production agent may need to make decisions, call tools, process events, maintain state, retry failed operations, communicate with other services, and continue working without a user waiting for every step.
At that point, the application needs infrastructure around the agent.
Kubernetes can provide much of the runtime foundation required for these workloads. Instead of building scheduling, service discovery, health management, scaling, networking, and workload isolation from scratch, teams can use Kubernetes as the execution platform and focus their engineering effort on the agent itself.
This article explains how to approach autonomous AI workloads on Kubernetes, what infrastructure should be reused, and where application-specific logic still needs to be built.
What Makes an AI Workload Autonomous?
A traditional application usually waits for an external request.
For example:
HTTP Request
|
v
API
|
v
Database
|
v
ResponseAn autonomous agent can continue working after the initial request.
A simplified workflow looks like this:
User Request
|
v
Agent
|
v
Plan Task
|
+----> Call Tool
|
+----> Process Result
|
+----> Call Another Tool
|
+----> Evaluate Result
|
+----> Continue
|
v
Complete TaskThe agent may run for seconds, minutes, or longer depending on the task.
It may also need to resume after a temporary failure.
This changes the infrastructure requirements significantly.
Why Not Build the Agent Infrastructure Yourself?
A common approach is to create a custom system for every AI application.
The team might build its own:
Worker scheduler
Retry mechanism
Service discovery
Health monitoring
Scaling system
Job manager
Configuration system
Secret management
Network routing
Logging infrastructure
This quickly becomes expensive to maintain.
Kubernetes already provides many of these primitives.
The goal is therefore not to make Kubernetes responsible for agent reasoning. The goal is to use Kubernetes for the infrastructure problems it already solves well.
Separate the Agent From the Runtime
A useful architecture starts with a clear separation.
AI Application
|
v
Agent Runtime
|
+--------------+--------------+
| | |
v v v
Tools State Model API
|
v
External Systems
Kubernetes PlatformThe agent runtime contains application logic.
Kubernetes manages the workload that runs that logic.
This distinction makes the architecture easier to maintain.
For example, the agent may contain code such as:
while (!task.Completed)
{
var action = await agent.PlanNextActionAsync(task);
var result = await toolExecutor.ExecuteAsync(action);
task = await agent.ProcessResultAsync(task, result);
}Kubernetes does not need to understand what PlanNextActionAsync() means.
It only needs to ensure that the service running this code is available, appropriately scaled, and properly isolated.
Choose the Right Kubernetes Workload
Not every autonomous agent should run as a Deployment.
The workload type should match the behavior of the application.
Deployment
Use a Deployment when the agent worker is continuously available.
Agent Worker
|
+-- Receives tasks
+-- Processes tasks
+-- Waits for next taskThis is useful for queue-driven agents.
Job
Use a Kubernetes Job when an agent execution has a clear beginning and end.
Task Created
|
v
Job Starts
|
v
Agent Executes
|
v
Task Completed
|
v
Job EndsThis is useful for isolated batch-style workflows.
CronJob
A CronJob is useful when autonomous work needs to start on a schedule.
For example:
Every hour
|
v
Start Agent
|
v
Check systems
|
v
Generate report
|
v
ExitThe important point is that the Kubernetes workload type should reflect the lifecycle of the agent.
Use a Queue for Autonomous Work
For many production systems, a queue is more useful than direct HTTP invocation.
Consider an invoice-processing agent.
Invoice Event
|
v
Queue
|
v
Agent Worker
|
+---- Validate Invoice
+---- Retrieve Customer
+---- Calculate Result
+---- Update System
|
v
CompletedThe queue separates event production from agent execution.
This provides several benefits.
If the agent becomes temporarily unavailable, events can remain queued.
If traffic increases, more workers can be started.
If one task fails, it can be retried without blocking unrelated tasks.
Scale Based on Workload, Not Just CPU
CPU-based autoscaling works well for many web applications, but autonomous AI workloads often have different bottlenecks.
An agent worker may spend much of its time waiting for:
Model responses
Database queries
External APIs
Tool execution
Queue messages
CPU utilization may therefore remain low even when the workload is overloaded.
Useful scaling signals include:
Queue Depth
Active Tasks
Task Wait Time
Model Request Rate
Model Latency
Tool Latency
CPU
Memory
GPU UtilizationFor a queue-driven agent, queue depth is often a better scaling signal than CPU.
For example:
Queue = 20 messages
Workers = 2
Queue = 500 messages
Workers = 20The exact scaling policy should be based on load testing rather than an arbitrary worker count.
Keep Agent State Outside the Pod
Autonomous agents often need state.
For example:
Task ID
Current Step
Previous Tool Result
Retry Count
User Context
Workflow StatusDo not rely on local pod memory for durable state.
A pod may be restarted or moved to another node.
A better architecture is:
Agent Worker
|
+---- Temporary execution state
|
v
Persistent State Store
|
+---- Task status
+---- Workflow state
+---- CheckpointsThis allows another worker to resume the task.
Add Checkpoints to Long-Running Tasks
Suppose an agent performs five operations:
1. Read customer data
2. Analyze account
3. Generate recommendation
4. Update CRM
5. Send notificationIf the pod fails after step 3, restarting from step 1 may be wasteful or unsafe.
Instead, store checkpoints:
Task: 10045
Step 1: Completed
Step 2: Completed
Step 3: Completed
Step 4: Pending
Step 5: PendingThe new worker can resume from the appropriate point.
This becomes especially important when tool calls have side effects.
Make Tool Calls Idempotent
Autonomous systems retry.
Network failures happen.
Model calls time out.
Workers restart.
Therefore, an agent may accidentally attempt the same operation more than once.
For example:
Agent
|
v
Create Payment
|
v
Timeout
|
v
Retry
|
v
Create Payment AgainIf the payment operation is not idempotent, this can become a serious production problem.
Use an idempotency key where the downstream service supports it.
For example:
task-10045-paymentThe service can recognize that the request has already been processed.
For operations without native idempotency support, maintain an application-level operation record.
Give Agents Limited Permissions
Autonomous does not mean unrestricted.
An agent should receive only the permissions required for its job.
For example:
Order Agent
Allowed:
- Read order
- Read shipment
- Create support ticket
Denied:
- Delete customer
- Modify payment
- Access employee records
- Execute arbitrary commandsThis can be enforced at multiple layers.
Application Layer
The tool service checks whether the agent is allowed to perform the operation.
Identity Layer
Use workload identities and IAM permissions where appropriate.
Kubernetes Layer
Use NetworkPolicies and namespace or workload isolation.
Infrastructure Layer
Restrict access to databases, APIs, and cloud services.
Defense in depth is important because an agent is making decisions dynamically.
Do Not Give the Agent a Kubernetes API Token
One particularly risky design is giving an autonomous agent broad Kubernetes API access.
An agent that needs to process customer orders does not need permission to create deployments or delete pods.
Keep the Kubernetes control plane separate from agent business capabilities.
If an operational automation agent genuinely needs Kubernetes access, use a narrowly scoped service account and RBAC permissions.
Join the conversation! Your thoughts help the community grow.