Production-grade guide to agent deployment patterns covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
Agent deployment patterns determine how autonomous software units are provisioned, updated, and retired across infrastructure. This matters when you're moving beyond single-agent prototypes to systems where multiple agents need consistent lifecycles, resource boundaries, and failure handling. This page covers the practical patterns for deploying agents at scale, organized by the operational tasks you'll face.
The most common starting point is ensuring the agent process starts reliably and persists across restarts. On systems using systemd, the pattern is straightforward:
# Enable the agent to start at boot
systemctl enable agent-service
# Start the service immediately
systemctl start agent-service
# Verify it's running
systemctl status agent-service
A frequent failure mode: the agent starts but exits immediately because it cannot reach its configuration backend. The service status will show failed with an exit code indicating connection refused or timeout. The journal typically logs the specific failure, often something like "failed to connect to configuration service at http://config:8080 after 30s".
When containerizing, docker run with standard flags handles the basics:
docker run -d \
--name agent-instance \
--restart unless-stopped \
-e AGENT_ENDPOINT=https://api.example.com/agents \
-e AGENT_TOKEN=${AGENT_TOKEN} \
-p 8080:8080 \
my-agent-image:latest
The --restart unless-stopped flag is critical; without it, the container disappears on host reboot. The -e flags inject environment variables at runtime; the agent image must be designed to read these. Omitting AGENT_TOKEN often results in authentication errors on the first API call, manifesting as "invalid or missing token" responses.
Agents need configuration without hardcoding values. The standard pattern involves external configuration sources that the agent reads at startup.
In Kubernetes, ConfigMaps provide a way to decouple configuration from image content:
apiVersion: v1
kind: ConfigMap
metadata:
name: agent-config
data:
agent_endpoint: "https://api.example.com/agents"
agent_timeout: "30"
log_level: "info"
The agent deployment mounts this ConfigMap and maps its keys as environment variables or file contents. The sharp edge: if the ConfigMap is updated after the agent is running, the agent continues using the old values until it is restarted. There is no automatic reconciliation; the operator must trigger a rollout or restart.
Secrets follow a similar pattern but with restricted access. Kubernetes Secrets store base64-encoded data and are mounted as files or environment variables. The agent typically reads the secret file path rather than the secret itself. A common mistake is mounting a Secret with incorrect permissions, causing the agent process to fail on read with "permission denied" errors.
For systems without native ConfigMap support, environment variable injection via the orchestrator is the fallback. In Docker Compose:
services:
agent:
image: my-agent-image
environment:
- AGENT_ENDPOINT=https://api.example.com/agents
- AGENT_TOKEN=${AGENT_TOKEN}
The ${AGENT_TOKEN} reference expects the host environment to provide the variable, typically through a .env file or orchestration platform secrets integration.
Deploying a new agent version requires careful handling to avoid downtime or inconsistent states. The most common pattern for Kubernetes-based deployments is the rolling update:
kubectl set image deployment/agent-instance \
agent-image=my-agent-image:v2.1.0
This command updates the container image reference in the Deployment spec and triggers a controlled replacement of pods. Each new pod starts, passes health checks, and takes traffic while old pods terminate. The kubectl rollout status deployment/agent-instance command monitors progress and blocks until the new version is fully ready.
If the new version introduces a bug, rollback is a single command:
kubectl rollout undo deployment/agent-instance
This reverts the Deployment to the previous image tag and initiates another rolling update in the opposite direction. The gotcha: rollback only works if the previous revision is still available in the Deployment's history. If multiple updates have occurred since the desired fallback, the history may have been pruned, and rollback reverts to the oldest available revision.
For systems without native rollout support, the pattern involves batch deployment and manual cutover. Deploy the new version alongside the existing one, verify functionality, then shift traffic via load balancer or DNS. The risk window exists between traffic shift and confirmation that all old instances have fully drained.
Running multiple agent instances requires a scaling mechanism. In Kubernetes, replica sets handle this natively:
# Scale to five instances
kubectl scale deployment/agent-instance --replicas=5
Kubernetes distributes pods across available nodes, respects node selectors and taints, and handles pod affinity if specified. The Horizontal Pod Autoscaler can adjust replicas based on custom metrics, but that requires metric infrastructure.
For platforms without Kubernetes, manual scaling or process managers are the pattern. With systemd, you might run multiple instances with different unit names:
systemctl start agent-service@1
systemctl start agent-service@2
systemctl start agent-service@3
Each instance reads the same unit file but with %i substitutions for index-specific paths or ports. The operator is responsible for ensuring port independence and distinct data directories.
Docker Swarm mode provides docker service scale:
docker service scale agent-service=6
This scales the service to six replicas, with the swarm scheduler distributing them across available nodes. The docker service ps agent-service command shows the desired and current state of each replica.
Knowing whether agents are alive and functioning is essential for automated deployment and incident response. Most agents expose a health endpoint, typically /healthz or /status. Probing this with curl is a standard verification pattern:
curl -f http://localhost:8080/healthz || echo "agent unhealthy"
The -f flag makes curl return a non-zero exit code on HTTP errors (4xx, 5xx), which is useful in scripts and orchestration logic. A successful response typically returns 200 OK with a minimal JSON body or plain text like "OK".
For deeper liveness information, many agents provide a /readyz endpoint that checks dependencies—database connectivity, external service reachability, configuration validity. A /readyz failure indicates the agent should not receive traffic, even if /healthz passes. Orchestration platforms integrate these endpoints; Kubernetes liveness and readiness probes configuration looks like:
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
readinessProbe:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
The sharp edge: probes that are too aggressive can cause infinite restart loops if the agent takes longer than the initialDelaySeconds to fully initialize. Probes that are too lenient delay failure detection, allowing traffic to reach an agent that cannot actually function.
Several failure modes catch operators off guard:
agent_timeout: 30, another with agent_timeout: 60) behave inconsistently. Debugging intermittent failures across instances often reveals this drift.ImagePullBackOff. The agent never runs, and the operator sees only the pull error, not the underlying auth configuration issue.200 OK to /healthz while its internal state is degraded—queues backing up, database connections leaking. The orchestrator marks it ready, traffic routes, and the agent becomes overwhelmed. This is particularly insidious because it passes all automated checks.When an agent is no longer needed, proper retirement prevents resource leaks and orphaned configurations.
In Kubernetes, deleting the Deployment removes associated Pods and, if using auto-generated Services, those as well:
kubectl delete deployment/agent-instance
The kubectl get all -l app=agent-instance command after deletion confirms removal. If the Deployment used a PersistentVolumeClaim for state, that PVC persists unless explicitly deleted or automated cleanup is configured.
For systemd services:
systemctl stop agent-service
systemctl disable agent-service
This stops the process and removes the boot-time enablement. The unit file and any associated data directories remain unless manually removed.
Docker containers require explicit removal:
docker stop agent-instance
docker rm agent-instance
Without the rm step, the container's filesystem persists, occupying disk space. Orphaned images accumulate similarly; docker image prune -a removes untagged images, but caution is advised as it may remove images in use by other running containers.
When agents have written to external systems—databases, message queues, storage buckets—retirement must include data migration or archival. There is no universal cleanup pattern; it depends on the agent's data footprint and compliance requirements. Always verify that no other system depends on the agent's outputs before final disposal.
This page was rewritten on 13 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy