agent-job

by Scalr

Helm chartv0.6.16App 1.14.0Verified publisher

A Helm chart for deploying the Scalr Agent on a Kubernetes cluster. It uses a job-based model, where each Scalr Run is isolated in its own Kubernetes Job.

About this chart

agent-job

A Helm chart for deploying the Scalr Agent on a Kubernetes cluster. It uses a job-based model, where each Scalr Run is isolated in its own Kubernetes Job.

See the official documentation for more information about Scalr Agents.

Table of Contents

  • Prerequisites
  • Installation
  • Overview
  • Architecture Diagram
  • Versioning Policy
  • Agent Task Naming
  • Custom Runner Image
  • High Availability
  • Performance Optimization
  • Termination
  • HTTP Proxy
  • Custom Certificate Authorities
  • Mutual TLS (mTLS)
  • Volumes
  • Security
  • Provider Network Mirrors
  • Network Requirements
  • Job History Management
  • Metrics and Observability
  • RBAC
  • Custom Resource Definitions
  • Planned Changes
  • Troubleshooting and Support
  • Configuration
  • Maintainers

Prerequisites

  • Kubernetes 1.35+ (both the control plane and all nodes running agent task pods)
  • Helm 3.0+
  • Optional: ReadWriteMany volume for Cache Volume Persistence

Installation

To install the chart with the release name scalr-agent:

# Add the Helm repo
helm repo add scalr-agent https://scalr.github.io/agent-helm/
helm repo update

# Install or upgrade the chart
helm upgrade --install scalr-agent scalr-agent/agent-job \
  --set agent.token="<agent-pool-token>"

Overview

The agent-job Helm chart deploys a Scalr Agent that uses a job-based architecture to execute IaC tasks in Kubernetes.

The chart consists of two Kubernetes resources: agent and agent task.

Agent

The agent is a Kubernetes Deployment, deployed by default as a single replica consisting of one container:

  • controller: The Scalr Agent process in controller mode, based on the scalr/agent image.

The agent controller is responsible for polling incoming tasks from Scalr and launching them as isolated Kubernetes Jobs.

See agent deployment template.

Agent Task

Each agent task is a Kubernetes Job created by the agent controller. It consists of two isolated containers:

  • runner: The environment where the run (Terraform/OpenTofu operations, OPA policies, shell hooks, etc.) is executed, based on the scalr/runner image.
  • worker: The Scalr Agent process in worker mode, that supervises task execution, using the scalr/agent image.

The task template is defined via a Custom Resource Definition(CRD). The agent controller uses this resource to create Jobs from a template fully managed by this Helm chart. The controller may patch the Job definition to inject dynamic resources, such as labels and annotations with resource IDs (run ID, workspace ID, etc.).

The runner and worker containers share a single disk volume, allowing the worker to provision the configuration version, providers, and software binaries required by the runner container.

The number of agent task Jobs depends on the active workload that the Scalr platform delegates to the agent pool to which the agent is connected.

See agent task Job CRD template.

Pros

  • Cost-efficient for bursty workloads — e.g., deployments with high number of Runs during short periods and low activity otherwise, as resources allocated on demand for each Scalr Run.
  • High multi-tenant isolation, as each Scalr Run always has its own newly provisioned environment.
  • Better observability, as each Scalr Run is tied to its own unique Pod.

Cons

  • Requires access to the Kubernetes API to launch new Pods.
  • Requires a ReadWriteMany Persistent Volume configuration for provider/binary caching. This type of volume is generally vendor-specific and not widely available across all cloud providers.

Architecture Diagram

Versioning Policy

This chart deploys the Scalr Agent using the scalr/agent image. The agent supports multiple runtimes beyond Kubernetes and is versioned independently from this chart.

Each new agent release triggers a new chart release with an updated appVersion. By default the chart deploys the matching agent image: agent.image.tag is empty and falls back to .Chart.AppVersion. Upgrade the agent by upgrading the chart to a release that ships the agent version you want.

The two changelogs cover different scopes:

  • Scalr Agent changelog — application-level changes and new Scalr platform functionality
  • CHANGELOG.md — chart-level changes: Kubernetes resources, values, and defaults

[!WARNING] Setting agent.image.tag to an agent version other than the chart's appVersion is not recommended. Each chart release is tested and coordinated with a specific agent version, and mismatched combinations may include breaking changes between the application and the chart's Kubernetes resources.

Agent Task Naming

When the agent controller spawns a Kubernetes Job for a Scalr Run, the Job is named using the pattern:

<basename>-<run-id>-<stage>

Where:

  • basename: Configurable prefix derived from the chart's fullname (defaults to scalr-agent). Override with task.job.basename.
  • run-id: Unique identifier assigned by the Scalr platform (e.g., run-v0p500fu3s9ban8s8).
  • stage: The execution stage (e.g., plan, apply, policy, etc).

If the final Job name after concatenation exceeds 63 characters (the Kubernetes Job name limit), the basename prefix will be omitted.

Examples:

Release Nametask.job.basenameResulting Job Name
scalr-agent(empty)scalr-agent-run-abcd1234-plan
prod-agent(empty)prod-agent-run-abcd1234-apply
scalr-agentmy-jobsmy-jobs-run-abcd1234-policy
scalr-agentmy-extra-long-....-basenamerun-abcd1234-policy

To customize the basename:

helm upgrade --install scalr-agent scalr-agent/agent-job \
  --set task.job.basename="custom-prefix"

Custom Runner Image

The chart uses the scalr/runner image by default to provision run environments (source). This is the image that hosts Terraform/OpenTofu, OPA policies, and shell hooks. You can override task.runner.image.* to point at a custom runner image.

A custom runner image must:

  • Include a user with UID/GID 1000. By default, Scalr images include a scalr user with 1000:1000.
  • Include /bin/sh and curl.
  • Include glibc 2.32 or later.

For OpenTofu/Terraform operations, it is recommended to also include git and ssh, which the CLI may use when downloading modules from remote Git servers.

Example override:

helm upgrade --install scalr-agent scalr-charts/agent-job \
  --set agent.token="<agent-token>" \
  --set task.runner.image.repository="registry.example.com/custom-runner" \
  --set task.runner.image.tag="v1.2.3"

Alternatively, install run-time tooling on demand via Workspace hooks. This avoids rebuilding the image but adds latency to every run.

High Availability

This section describes strategies for hardening the deployment for high availability (HA).

Separate Controllers and Task Pods

It is recommended to run agent controller pods and task job pods on separate node pools. This prevents resource-intensive run workloads from competing with controllers for CPU and memory, which could delay run scheduling or cause controller eviction. It also allows upgrading or resizing the task node pool without interrupting the controllers that schedule incoming runs.

Use agent.nodeSelector and task.nodeSelector to pin each to its own node pool. The role key below is an arbitrary custom label — apply it to your nodes first (kubectl label nodes <node> role=main), or substitute a built-in cloud label such as eks.amazonaws.com/nodegroup, cloud.google.com/gke-nodepool, or agentpool.

agent:
  nodeSelector:
    role: main
task:
  nodeSelector:
    role: scalr-agent-runs

With task pods on a dedicated node pool, you can also scale that pool down to zero during periods of inactivity and let the cluster autoscaler provision nodes on demand when runs arrive. For clean scale-to-zero, taint the task nodes (kubectl taint nodes <node> dedicated=scalr-agent-runs:NoSchedule) and add a matching toleration under task.tolerations, so unrelated workloads can't land there and pin the nodes:

task:
  nodeSelector:
    role: scalr-agent-runs
  tolerations:
    - key: dedicated
      operator: Equal
      value: scalr-agent-runs
      effect: NoSchedule

Multiple Controller Replicas

By default the chart runs a single controller replica (agent.replicaCount: 1). Increasing the replica count distributes the run scheduling load and ensures the agent pool remains available during voluntary disruptions such as node upgrades or pod restarts.

helm upgrade --install scalr-agent scalr-agent/agent-job \
  --set agent.replicaCount=2

When agent.replicaCount > 1, the chart automatically creates a PodDisruptionBudget (controlled by agent.podDisruptionBudget) that keeps at least one controller available during voluntary disruptions.

For zone-level resilience inside a single cluster, combine replicaCount with agent.topologySpreadConstraints so replicas land in different availability zones (and on different nodes within a zone). This is the recommended single-cluster HA configuration:

agent:
  replicaCount: 2
  topologySpreadConstraints:
    - maxSkew: 1
      topologyKey: topology.kubernetes.io/zone
      whenUnsatisfiable: ScheduleAnyway
      labelSelector:
        matchLabels:
          app.kubernetes.io/name: agent-job
    - maxSkew: 1
      topologyKey: kubernetes.io/hostname
      whenUnsatisfiable: ScheduleAnyway
      labelSelector:
        matchLabels:
          app.kubernetes.io/name: agent-job

whenUnsatisfiable controls what happens when the spread constraint cannot be satisfied:

  • ScheduleAnyway - soft guarantee, pods will co-locate on a single zone/node if no better option exists
  • DoNotSchedule - hard guarantee, pods stay Pending until the spread can be satisfied

Use whenUnsatisfiable: DoNotSchedule if you require strict spread (pods stay Pending rather than co-locating).

Multi-Cluster HA

For high availability within a single cluster, prefer the single-release configuration above (replicaCount + topologySpreadConstraints + the auto-created PDB). Running multiple Helm releases inside the same cluster duplicates operational surface (values, rollouts, PVCs, metrics) without buying isolation that a dedicated node pool with taints doesn't already provide.

For multi-cluster or multi-region resilience, install agent-job once per cluster against the same Scalr agent pool. Each release carries its own token, PVCs, and upgrade cadence; the Scalr agent pool sees them as additional controllers and load-balances scheduling across all of them. A cluster-level failure or maintenance window then takes out at most one slice of capacity.

Performance Optimization

The following additional configurations are recommended to optimize Scalr Run startup time and overall chart performance.

Optimize Run Startup Time

This chart uses Jobs to launch Scalr Runs, so fast Job launch is critical for low Scalr Run startup latency. Common bottlenecks that may introduce latency include slow image pull times on cold nodes. To optimize this, you can:

  • Use image copies in an OCI-compatible registry mirror (Google Container Registry, Amazon Elastic Container Registry, Azure Container Registry, and similar) located in the same region as your node pool. This enables faster pull times and reduces the risk of hitting Docker Hub rate limits.
  • Enable Image Streaming (GKE only) to improve Job launch time.
  • Build and use a smaller runner image tailored to your requirements. The default task.runner.image includes a wide variety of tools, including cloud CLIs (GCE, AWS, Azure), scripting language interpreters, and more, which makes it a relatively large image and may negatively impact image pull times.
  • Use a DaemonSet to preemptively cache all images used in this chart (scalr/agent, scalr/runner) on clusters with a fixed number of nodes.
  • Use buffer pods on clusters wi

Deploy agent-job with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has agent-job on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartagent-job is pinned at v0.6.16 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply