Skip to main content

How and when to scale

Written by Aron Day

On a standard self-hosted install, 3B currently provides built-in KEDA autoscaling only for Edge and workers. Install and verify KEDA before setting autoscaling.enabled: true in 3B v10.2.0 or later.

Your team sets replica limits for self-hosted 3B and provides the CPU, memory, and disk those pods need, including when autoscaling is on. The system overview describes each service.

For the 3B Helm values and rollout steps, start with Install KEDA for 3B autoscaling. To investigate a replica count, see Common questions about 3B autoscaling.

When to scale

Symptom

Helm value to raise

Executions wait for a free worker slot

worker.replicas

The UI or API slows under heavy traffic

api.replicas

Webhooks respond slowly or time out

edge.replicas

Set worker.replicas to cover sustained demand. Each default worker runs one execution at a time and requests 1 vCPU and about 4 GiB of RAM. To run more executions per pod, increase worker.cpus. On v10.3.0, this also requires a runtime class for per-step limits.

To scale the API automatically, configure your own HorizontalPodAutoscaler. Start with a 50% average CPU target and a 15-minute scale-down stabilization window.

Keep in-cluster Postgres, nginx, and Blobstore at one replica. For Blobstore pressure, raise blobstore.resources or expand its volume. Raise the memory request and limit together, and check the node capacity. For a highly available database, use external Postgres.

Autoscaling

Our defaults follow the approach we use in 3B Cloud.

  • Edge targets 50% average CPU and 50% usage of each permit pool (execution and response).

  • Workers scale with demand for execution slots and aim for one spare worker. For hourly jobs, set worker.topOfHourPrewarmReplicas to bring workers up before the hour.

Install KEDA 2.21 or later and Metrics Server first. Remove any HorizontalPodAutoscaler you set up for Edge or workers.

With the default rollout, webhooks can briefly fail while Kubernetes replaces the only ready Edge pod. Edge can drop to one replica when you first enable autoscaling, even with a higher minimum.

Metrics and authentication

When autoscaling is enabled, Edge and the orchestrator push 3B’s scaling gauges every 10 seconds. KEDA queries edge_admission_utilization and orchestrator_worker_slots_wanted using the stack label set to the chart’s stackName. Preserve these names and the label. Every Prometheus replica KEDA queries needs a sample at least every 30 seconds.

For direct ingestion into Prometheus 3 or later, enable --web.enable-otlp-receiver, keep default metric name translation, and set autoscaling.otlpMetricsEndpoint to the Prometheus URL plus /api/v1/otlp/v1/metrics. If your HTTP proxy cannot reach the endpoint, add its host to httpProxy.noProxy.

For push credentials, set autoscaling.otlpMetricsHeaders. This example sends Authorization: Bearer <token> using a Kubernetes Secret and adds a fixed tenant header. The chart encodes literal values. Percent-encode commas and % in the Secret value yourself.

autoscaling:
  otlpMetricsHeaders:
    - name: Authorization
      value: Bearer
      secretKeyRef: { name: otlp-auth, key: token }
    - name: X-Scope-OrgID
      value: tenant-a

For query credentials, create a KEDA TriggerAuthentication in the 3B namespace. Set autoscaling.triggerAuthentication to its name and add any required metadata, such as authModes: bearer, to autoscaling.prometheusMetadata.

Managed Prometheus

Use an in-cluster Collector if your store requires signed requests, cloud identity, a private certificate authority, or another ingestion protocol. Point autoscaling.otlpMetricsEndpoint at its otlp receiver and configure the exporter for your provider. 3B pushes metrics over OTLP even when the provider’s example uses a scrape receiver. KEDA can query the store directly using a TriggerAuthentication with pod identity.

For Google’s Telemetry API, add this transform processor to the Collector’s metrics pipeline. It replaces the periods in 3B’s gauge names with the underscores KEDA queries.

processors:
  transform/3b:
    metric_statements:
      - context: metric
        statements:
          - set(name, "edge_admission_utilization") where name == "edge.admission.utilization"
          - set(name, "orchestrator_worker_slots_wanted") where name == "orchestrator.worker.slots.wanted"

Per-step resource limits

Self-hosted installs leave the runtime class empty by default. To enforce per-step limits of 1 vCPU and 2 GiB of RAM, give each container write access to its own cgroup v2 subtree.

We recommend enabling limits when you scale workers. Set worker.cpus to the CPUs per worker pod. Each CPU provides one execution slot, less one slot per full eight CPUs. Each slot gets sandboxd.stepMemoryMiB of memory (2048 MiB by default). The chart sizes Pony with the slot count.

Configure a dedicated runtime handler on every node that can run API or worker pods. For containerd 2.x with configuration version 3, merge this into the node configuration.

[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.sandboxd-runc]
runtime_type = "io.containerd.runc.v2"
cgroup_writable = true

[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.sandboxd-runc.options]
SystemdCgroup = true

Keep writable cgroups on this dedicated runc handler and retain the chart’s user namespaces and container limits. Inside the container, sandboxd sets limits for each execution and launches the bundled gVisor runtime.

On K3s, use sudo with your editor to open /var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.tmpl. Keep {{ template "base" . }} at the top and add the TOML above. Configure nodes through your usual maintenance process before scheduling pods with the handler. K3s containerd configuration

Then select the handler in Helm.

sandboxd:
  runtimeClassName: sandboxd-runc

The chart selects this RuntimeClass for API and worker pods. If you already set it, prepare all eligible nodes before upgrading. Workers require working cgroup delegation to start. If cgroup creation or process placement fails later, sandboxd drains and the worker stops taking new work. These limits apply to workflow executions.

Each worker pod shares one sandboxd and one Pony across its slots. For one worker per node, set worker.cpus to the node’s CPU count, up to 32. Budget the configured step memory and 160 MiB for Pony per slot, plus about 2 GiB per pod. Allow 40 GiB of disk per slot, space for caches, and 30 GiB for the OS and images.

This 8-vCPU, 32-GiB example runs seven executions and leaves a CPU for the kubelet and node agents.

sandboxd:
  runtimeClassName: sandboxd-runc
worker:
  cpus: 8

Set worker.replicas to the number of worker nodes. For Kubernetes to enforce disk capacity, set sandboxd.ephemeralStorageGiB to at least the caches plus 40 GiB per slot (292 GiB here). Sandboxd also stops a build that exceeds its share.

On the single-server install, pass this as an extra values file via EXTRA_VALUES_FILE in /opt/3b/.env. After rollout, verify sandboxd no longer reports disabled cgroup enforcement and that a test execution receives the expected CPU and memory limits.

Some chart versions allow worker.cpus above 1 with an empty sandboxd.runtimeClassName. The executions in a pod then share its CPU and memory instead of each having its own limits. The chart still sizes the pod’s memory for every execution at its step memory, but a step can use more than its share. A busy step can slow the others in its pod. A step that exhausts the pod’s memory can restart the pod along with every execution in it, and those executions then run again from the start. Use per-step resource limits where your nodes support them, and shared resources where they don’t.

Worker node disk throughput

All builds and executions on a node share its disk. First builds write the base image and its dependencies. Later builds can reuse cached layers for the base images 3B bundles, including all standard templates. Other images unpack every layer on each build. Publishing a large workflow can start several builds at once.

Plan for about 125 MiB/s of sustained write throughput per two concurrent builds on a node, or about 1,000 MiB/s for 16 builds. Kubernetes can schedule disk capacity through sandboxd.ephemeralStorageGiB. Size the disk’s throughput separately so a burst of builds doesn’t slow every execution.

Did this answer your question?