> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tembo.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> The services Tembo runs in your cluster, and how the host controller runs agent hosts.

The `tembo` Helm chart installs the platform in one namespace. Agent sessions don't run in the cluster: they run in virtual machines on **agent hosts**, cloud instances that the chart's **host controller** launches, scales and replaces.

## Services in the cluster

| Service | What it does |
| - | - |
| **Web** | The Tembo web app. |
| **API** | Product workflows, sign-in, integrations, webhooks, the Tembo MCP server at `/mcp`, and the endpoints agent hosts call. |
| **Worker** | Background jobs, such as syncing repositories. |
| **Cron** | Scheduled jobs, such as cleanup and scheduled project builds. |
| **Migrations** | A job that updates the database schema on every install and upgrade. |
| **Host controller** | Launches and tracks agent hosts. |
| **Sandbar** | Serves Computer previews and `tembo service` URLs. |
| **LiteLLM** | Sends model requests made with an organization's AWS Bedrock, GCP Vertex AI or OpenRouter credentials. |
| **Postgres** | The database. Bundled, or a managed database you provide. |
| **Redis** | Queues, caching and live updates. Bundled, or a managed Redis you provide. |

The chart generates the secrets the platform needs once, such as signing and encryption keys and the GitHub webhook secret, and keeps them across upgrades.

Tembo keeps project images, session snapshots, file uploads and agent assets in one object storage bucket (S3 or GCS), which the Terraform module creates.

Your Helm values describe the whole install. The chart passes the same configuration to agent hosts through a Kubernetes Secret, which each host reads when it starts. Model providers, workspaces and members are set up in the Tembo app.

## Agent hosts

Agent hosts are EC2 instances on AWS, or Compute Engine instances on GCP, started from Tembo's agent host image. They need nested virtualization, and keep VM disks, snapshots and saved memory on the instance's local NVMe. They connect directly to Postgres, Redis and Sandbar.

You describe them in your Helm values with two resources. The Terraform module's Helm values create one of each, named `default`:

* A **host class** says what to launch: the image, instance types, subnets, security groups, instance profile and root volume.
* A **pool** says how many to run: `minHosts`, `maxHosts`, and `minIdleMemory`, the free memory to keep for new sessions.

The controller creates a **host** resource for each instance it launches:

```bash theme={null}
kubectl -n tembo get tembohostclasses,tembohostpools,tembohosts
```

### Lifecycle

1. **Launch.** The controller starts an instance with the class's settings and tags it as its own. It only manages instances it created.
2. **Configure.** The host reads its configuration from a Kubernetes Secret through the cluster's API, with a short-lived token the controller gives it at launch.
3. **Register.** The host registers with your install and becomes `Ready`, usually within a few minutes. The controller replaces a host that doesn't register within 15 minutes.
4. **Run sessions.** The host claims sessions and runs each one in its own virtual machine.

### Scaling

The controller sizes each pool by memory: the memory its sessions use, plus the memory waiting sessions need, plus `minIdleMemory`. When that's more than the pool's hosts provide, it launches another host, up to `maxHosts`. It never goes below `minHosts`.

When a pool has more hosts than it needs, the controller removes a host that has been idle for `disruption.idleAfter` (10 minutes by default): no session virtual machines, agent turns or host jobs. Warm VMs don't count. It removes the newest idle host, one per pool at a time.

To scale to zero, set both `minHosts: 0` and `minIdleMemory: 0` (see [Agent hosts](https://docs.tembo.io/features/self-hosted/kubernetes/configuration.md#agent-hosts)).

### Scheduled minimum hosts

To keep hosts running during busy periods, such as working hours, add schedules to a pool. Each one raises the pool's minimum for a period that starts on a cron schedule, so the first sessions of the day don't wait for a host to start. Outside its periods, the pool scales as usual. Chart 1.6.0 and later.

```yaml theme={null}
compute:
  hostPools:
    default:
      minHosts: 0
      maxHosts: 10
      minHostsSchedules:
        - schedule: '0 9 * * 1-5'    # 09:00, Monday to Friday
          timeZone: America/New_York # IANA name; unset uses UTC
          duration: 9h
          minHosts: 3
```

* The pool keeps the highest of `minHosts` and each active schedule's `minHosts`, up to `maxHosts`. Schedules never lower `minHosts` or change `maxHosts`.
* Hosts launch when a period starts. When it ends, the extra hosts are removed once idle, like any others.
* `schedule` uses standard five-field cron syntax. A pool can have up to 20 schedules.
* A schedule that doesn't parse, or names an unknown time zone, sets the pool's `Ready` condition to `False` with reason `InvalidMinHostsSchedule`. The pool keeps using its other schedules.

On an existing install, [apply the chart's CRDs](https://docs.tembo.io/features/self-hosted/kubernetes/upgrade-guide.md#upgrade) when you upgrade to 1.6.0, before you add schedules.

### Replacing hosts

Hosts read their image and configuration only when they start. Within about five minutes of a change that reaches them, such as the GitHub App, your hostname, the database or a new agent host image, the controller marks running hosts `Drifted` and replaces them, as many at a time as the pool's disruption budget allows (one by default):

1. The pool launches a replacement while the old host keeps taking sessions. If `maxHosts` leaves no room, the old host is cordoned right away and replaced once it's gone.
2. Once the replacement is ready, the old host is cordoned: it keeps serving its sessions, but new sessions go to other hosts.
3. Once the old host has been idle for the pool's idle period, the controller drains and terminates it.

Draining a host stops new sessions, lets running agent turns finish, stops its virtual machines and uploads their snapshots to object storage. A drain still going after the pool's `drainTimeout` (105 minutes by default) is marked `DrainStalled`. If a session starts on a draining host, the controller keeps the host.

### Managing hosts by hand

```bash theme={null}
# Keep a host from being removed or replaced
kubectl -n tembo annotate tembohost <host> hosts.tembo.io/do-not-disrupt=true

# Replace a host now
kubectl -n tembo delete tembohost <host> --wait=false

# Terminate a host without draining it. This ends the sessions running on it.
kubectl -n tembo annotate tembohost <host> hosts.tembo.io/force-terminate=true
```

## Sessions on a host

* **Stopping.** When a session goes idle, its virtual machine stops. The host saves a snapshot of its disk and memory, and uploads the disk to object storage.
* **Resuming.** On the same host, a session resumes from saved memory, with its processes still running. On another host, for example after its host was replaced, it resumes from the disk in object storage, without the processes that were running.
* **Project images.** A project build stores an image of the project's environment in object storage. Hosts download it on first use and keep a copy, so later sessions start in seconds.
* **Warm VMs.** For projects with **Warm pool** on, hosts keep virtual machines booted from the project's image, ready for the next session.

Saved memory only restores on a host with the same CPU, so keep all hosts on one processor generation (see [Instance types](https://docs.tembo.io/features/self-hosted/kubernetes/configuration.md#instance-types)).

***

## Need Help?

If you run into any issues, contact [support@tembo.io](mailto:support@tembo.io).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.