Self-hosted agents are available to Enterprise customers only. See pricing for details.
How It Works
KEDA polls the env zero agent queue state endpoint on a fixed interval and creates ACA job executions when deployment tasks are queued. Each container picks up one task, runs it to completion, and exits. When the queue is empty, no containers run.Prerequisites
- Azure CLI installed and authenticated (
az login) - Azure subscription with Contributor access
- An env zero agent pool with a valid agent access token. See Self-Hosted Agents Overview for how to create an agent pool and generate a secret.
Setup
Create a Container Apps environment
Create the job configuration file
Save the following as
env0-aca-job.yaml. Replace <YOUR_AGENT_ACCESS_TOKEN> with the agent access token generated for your agent pool, <YOUR_STATE_ENCRYPTION_KEY_BASE64> with a base64-encoded encryption key, and <X.Y.Z> with the agent version you want to pin to.env0-aca-job.yaml
Pin
image to a specific agent version rather than :latest to avoid silent upgrades during a running deployment. See the env0 deployment agent releases for current tags.Configuration Reference
KEDA Scaling Parameters
| Parameter | Default | Description |
|---|---|---|
pollingInterval | 30 | Seconds between KEDA polls of the queue state endpoint. |
maxExecutions | 10 | Maximum concurrent agent containers. |
minExecutions | 0 | Set to 1 or higher to keep warm containers running. |
replicaTimeout | 3600 | Maximum seconds a container can run before forced termination. |
targetValue | 1 | Tasks per container. 1 means one container per pending task. |
activationTargetValue | 0 | Metric threshold that activates scaling from zero. |
Container Resources
| Parameter | Default | Description |
|---|---|---|
cpu | 2 | CPU cores per container. |
memory | 4Gi | Memory per container. |
Environment Variables
| Variable | Required | Description |
|---|---|---|
AGENT_ACCESS_TOKEN | Yes | Agent authentication token. Stored as an ACA secret and referenced by secretRef. |
ENV0_STAGE | Yes | Determines which env zero API endpoint the agent connects to. Use prod for production. |
ENV0_STATE_ENCRYPTION_KEY | Yes | Base64-encoded encryption key for deployment state. Must be identical across all agent replicas. |
DEPLOYMENT_LOGS_LOG_LEVEL | No | Set to debug for verbose agent logging. |
Monitoring
List running and completed executions:Troubleshooting
No containers start when deployments are queued
Check the KEDA system logs for the Container Apps environment:api returned 401: the agent access token is incorrect or has been revoked. Generate a new secret and update the job configuration.- No KEDA activity logged: verify the job was created with
triggerType: Event.
A container starts but fails immediately
Check the container logs for the specific error. Common causes:- Missing
ENV0_STAGE: deployment commands build URLs from this variable and produce broken hosts when it is unset. Set it explicitly toprodfor production. - Missing
ENV0_STATE_ENCRYPTION_KEY: the agent exits immediately with an error. - Wrong
AGENT_ACCESS_TOKEN: the agent starts but receives 401 on API calls.
Cleanup
To remove all resources created for this setup:Next Steps
- Self-Hosted Agents Overview - Create agent pools and manage authentication secrets.
- Custom/Optional Configuration - Additional agent configuration options.
- Self-Hosted Agents Monitoring - Monitor agent health and deployments.