> For the complete documentation index, see [llms.txt](https://docs.controltheory.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources/kubernetes.md). Agents can also search and read this documentation through its [MCP server](https://docs.controltheory.com/~gitbook/mcp).

# Kubernetes

Kube ahoy!

Collect container logs, cluster events and topology from a Kubernetes cluster with an in-cluster agent, along with the OpenTelemetry (OTLP) logs and traces your pods send to it, and optionally metrics: Prometheus metrics from your nodes and workloads, and OpenTelemetry (OTLP) metrics your pods push to the agent.

### How it works

The **ControlTheory agent** runs inside your cluster and forwards data to Dstl8. It has two components:

* **DaemonSet**: runs on every node. It collects pod and container logs, and receives OTLP from applications on its node (see [Send telemetry from your pods](#send-telemetry-from-your-pods)). With metrics turned on, it also scrapes its node and accepts Prometheus Remote Write.
* **Cluster component**: runs once per cluster to collect Kubernetes events, metadata and [topology](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/topology.md) snapshots (how your workloads, pods, services and nodes connect).

You can install both (recommended, the default), or either one on its own.

### What the agent collects

| Data                             | Collected by                    | Notes                                                                                                                                                                                                  |
| -------------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Pod and container logs           | DaemonSet                       | Every container's stdout/stderr on the node. Lines up to 100 KiB; the agent's own pods are left out.                                                                                                   |
| Logs your pods send over OTLP    | DaemonSet                       | Always on.                                                                                                                                                                                             |
| Traces your pods send over OTLP  | DaemonSet                       | On when your plan includes Traces. Needs agent v1.4.0 or later. See [Sending traces](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/traces/sending-traces.md#kubernetes-agent). |
| Kubernetes events                | Cluster component               | See [Events](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/events.md).                                                                                                         |
| Topology                         | Cluster component               | See [Topology](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/topology.md).                                                                                                     |
| Prometheus metrics               | DaemonSet and cluster component | Off until you turn on **Collect Prometheus metrics**. See [Metrics](#metrics).                                                                                                                         |
| Metrics your pods send over OTLP | DaemonSet                       | Off until you turn it on. See [Metrics](#metrics).                                                                                                                                                     |

#### Access the agent needs

The agent only reads from the Kubernetes API. Both components can `get`, `list` and `watch`:

* pods, namespaces and nodes (the cluster component also services);
* Deployments, ReplicaSets, DaemonSets and StatefulSets;
* Jobs and CronJobs;
* events;
* Ingresses (cluster component only).

With **Collect Prometheus metrics** on, the install command adds read-only access to the kubelet's metrics (`nodes/metrics`) and, for the cluster component, to endpoints and EndpointSlices to find scrape targets. The agent never reads Secrets or ConfigMaps and has no write access to your resources.

### Add a Kubernetes source

#### 1. Create the source in Dstl8

From **Sources**, click **Add Source** and select **Kubernetes**. Configure the source (turn on **Collect Prometheus metrics** here if you want metrics) and complete setup. Dstl8 provides:

* Organization ID
* DaemonSet and cluster admission tokens
* Your organization's API endpoint and the source ID
* A ready-to-run install command

#### 2. Install the agent

With `kubectl` configured against the target cluster, run the install script (the UI provides this command with your values prefilled):

```bash
./install.sh \
  -i <org-id> \
  --ds-token <ds-token> \
  --cluster-token <cluster-token> \
  --org-api-endpoint <org-api-url> \
  --cluster-name <name> \
  -e <env> \
  --source-id <source-id>
```

The agent installs via Helm into the `controltheory` namespace by default.

#### 3. Verify

Check the rollout:

```bash
./install.sh -o status
```

In the Dstl8 UI, the source shows **Listening for telemetry** until the agent connects and starts forwarding, then turns **Healthy**. Streams appear as pods write logs. Typical stream types include Deployments, DaemonSets, StatefulSets and Jobs. Then [assign the streams to a workspace](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources.md#assigning-streams-to-workspaces).

### Send telemetry from your pods

The DaemonSet listens for OTLP on two ports:

| Port   | Protocol  |
| ------ | --------- |
| `1757` | OTLP/gRPC |
| `1758` | OTLP/HTTP |

Applications can reach the agent on their own node in two ways:

* **The agent's Service** (works with or without host ports). With the installer's defaults it is `aigent-ds` in the `controltheory` namespace. Traffic to it always stays on the sender's own node.

  ```yaml
  env:
    - name: OTEL_EXPORTER_OTLP_ENDPOINT
      value: http://aigent-ds.controltheory.svc.cluster.local:1758
    - name: OTEL_EXPORTER_OTLP_PROTOCOL
      value: http/protobuf
  ```
* **The node's address** (needs host ports, which the installer turns on by default). Pass the node IP to the pod with the downward API:

  ```yaml
  env:
    - name: NODE_IP
      valueFrom:
        fieldRef:
          fieldPath: status.hostIP
    - name: OTEL_EXPORTER_OTLP_ENDPOINT
      value: http://$(NODE_IP):1758
    - name: OTEL_EXPORTER_OTLP_PROTOCOL
      value: http/protobuf
  ```

Use port `1757` with `OTEL_EXPORTER_OTLP_PROTOCOL=grpc` if you prefer gRPC. Logs and traces sent this way are collected as they arrive (traces when your plan includes them; see [Sending traces](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/traces/sending-traces.md#kubernetes-agent)). Metrics are collected only once you turn them on (see below).

If ports `1757` and `1758` are already taken on your nodes, install with `--no-host-port`. Pods can still use the Service.

### Metrics

A Kubernetes source collects no metrics until you ask:

* **Collect Prometheus metrics** (a switch on the source, when you create it or under **Edit**) scrapes the kubelet, cAdvisor, node-exporter and kube-state-metrics, and accepts Prometheus Remote Write. The install command then carries `--prom-metrics`, so **re-run it after changing the switch**.
* **GPUs and model servers** is on whenever the switch is: it finds NVIDIA and AMD GPU exporters and vLLM model servers on every node. See [GPUs and Model Servers](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/metrics/gpus-and-model-servers.md).
* **Metrics your pods push over OTLP** are turned on with the CLI: `dstl8 sources metrics <source> --prom-metrics --otlp-metrics` (`--otlp-metrics` alone turns Prometheus metrics off). This needs no reinstall.

See [Collecting metrics](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/metrics/collecting.md) for what each path collects, the Remote Write port, and the agent version each needs.

### Install options

| Flag                  | Description                                                                                                                        |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `-i, --org-id`        | Organization identifier (required)                                                                                                 |
| `--org-api-endpoint`  | Your organization's API endpoint URL (required)                                                                                    |
| `--cluster-name`      | Name to identify this cluster (required)                                                                                           |
| `-e, --env`           | Deployment environment, e.g. `prod`, `staging` (required)                                                                          |
| `--source-id`         | The Kubernetes source this agent reports to (required)                                                                             |
| `--ds-token`          | DaemonSet admission token (required for `ds` / `both`)                                                                             |
| `--cluster-token`     | Cluster admission token (required for `cluster` / `both`)                                                                          |
| `-t, --type`          | Install `ds`, `cluster`, or `both` (default: `both`)                                                                               |
| `-n, --namespace`     | Kubernetes namespace (default: `controltheory`)                                                                                    |
| `--no-host-port`      | Don't expose OTLP ports (`1757` / `1758`) on nodes                                                                                 |
| `--release-suffix`    | Suffix the Helm release names, to install a second agent set in the same cluster (see [below](#a-second-agent-set-in-one-cluster)) |
| `--kubeconfig`        | Path to kubeconfig (default: `~/.kube/config`)                                                                                     |
| `--helm-version`      | Pin a specific Helm chart version (default: latest stable)                                                                         |
| `--prom-metrics`      | Allow Prometheus metrics collection (what is collected is set on the source; see [Metrics](#metrics))                              |
| `--prom-metrics-port` | Prometheus remote\_write port on the DaemonSet, 1024–65535 (default: `9090`; must match the source; requires `--prom-metrics`)     |
| `-d, --debug`         | Verbose output                                                                                                                     |

The installer stops with an error on an option it doesn't recognize, so a typo never turns into an install that silently lacks what you asked for. Run `./install.sh --help` for the full list.

### Other operations

```bash
./install.sh -o preflight     # check node capacity, taints, and schedulability before install
./install.sh -o status        # report on current agent state
./install.sh -o uninstall     # remove the agent
```

Run **preflight** on large or constrained clusters to surface scheduling issues — node capacity, taints, and overprovisioned pods — before committing to install.

### Updating the agent

The agent ships as two Helm charts — `aigent-ds` (DaemonSet) and `aigent-cluster` (cluster component) — published to the ControlTheory chart repository at `https://control-theory.github.io/helm-charts`. The two charts are versioned in lockstep; always upgrade both together.

Check what you're running and what's available:

```bash
helm list -n controltheory            # installed releases and chart versions
helm repo update ct-helm
helm search repo ct-helm              # latest published versions
```

(`./install.sh -o status` also reports the installed release versions.)

#### Option 1: Re-run the install script (recommended)

`install.sh` uses `helm upgrade --install` and refreshes the chart repository on every run, so re-running your original install command upgrades the agent in place — same flags, same tokens, latest chart:

```bash
./install.sh \
  -i <org-id> \
  --ds-token <ds-token> \
  --cluster-token <cluster-token> \
  --org-api-endpoint <org-api-url> \
  --cluster-name <name> \
  -e <env> \
  --source-id <source-id>
```

If your saved command came from an older version of this page: `--config-endpoint` now stops the installer. `--data-endpoint` is still accepted, but it's for local development only and overrides where the agent sends data, so remove it as well. Then add `--org-api-endpoint` and `--source-id`, or get a fresh command as below.

Don't have the command handy? Open **Sources** in the Dstl8 UI, open the Kubernetes source's actions menu, and select **Install Script**, or run `dstl8 sources install-script <source>`. Either returns the same command with your values prefilled, including any metrics settings. To upgrade to a specific chart version instead of the latest, add `--helm-version <version>`.

#### Option 2: Upgrade with Helm directly

If you manage the releases with Helm yourself (or in CI), upgrade both charts in the install namespace:

```bash
helm repo add ct-helm https://control-theory.github.io/helm-charts
helm repo update ct-helm

helm upgrade aigent-ds ct-helm/aigent-ds -n controltheory --reuse-values
helm upgrade aigent-cluster ct-helm/aigent-cluster -n controltheory --reuse-values
```

`--reuse-values` carries forward the values the install script originally set (admission tokens, endpoints, cluster name), so you don't need to re-supply them. Pin a version with `--version <version>` on each command. If you installed into a different namespace, adjust `-n` accordingly.

{% hint style="warning" %}
`--reuse-values` keeps your previous values but does **not** pick up new chart defaults introduced by a release. If release notes mention new configuration options, prefer re-running the install script (Option 1), which re-applies every value explicitly on top of fresh chart defaults.
{% endhint %}

#### Verify and roll back

After upgrading, confirm the pods are healthy and the source stays **Healthy** in the Dstl8 UI:

```bash
kubectl get pods -n controltheory
./install.sh -o status
```

If something goes wrong, Helm keeps the previous release revision — roll back either chart:

```bash
helm rollback aigent-ds -n controltheory
helm rollback aigent-cluster -n controltheory
```

### A second agent set in one cluster

To report one cluster to two Dstl8 sources at once, install a second agent set with its own namespace, its own release names and no host ports. Use the second source's install command and add these flags:

```bash
./install.sh \
  -i <org-id> \
  --ds-token <ds-token> \
  --cluster-token <cluster-token> \
  --org-api-endpoint <org-api-url> \
  --cluster-name <name> \
  -e <env> \
  --source-id <second-source-id> \
  -n <second-namespace> \
  --release-suffix <suffix> \
  --no-host-port
```

* `--release-suffix` (lowercase letters, digits and `-`) gives the second set its own release names. Without it the install fails, because the first set already uses the default names.
* `--no-host-port` is needed because only one agent per node can hold ports `1757` and `1758`. Without it, the second set's pods stay **Pending**.

Each set reads every container's logs, so each source receives the full set.

### Troubleshooting

| Symptom                                                                             | What to check                                                                                                                                                                                                                                                                                                                                                             |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Source stays **Listening for telemetry**                                            | Run `./install.sh -o status` and `kubectl get pods -n controltheory`. Check the agent's logs (`kubectl logs -n controltheory -l app.kubernetes.io/instance=aigent-ds`) for connection errors: the cluster needs outbound HTTPS (port 443) to Dstl8, so check proxies and egress rules. Make sure the command was copied in full, with the right tokens and `--source-id`. |
| DaemonSet pods stuck **Pending**                                                    | Run `kubectl describe pod` on one. The usual causes are a node out of CPU or memory, a taint the pod doesn't tolerate, or host ports `1757` / `1758` already in use on the node. For the last, re-run the install with `--no-host-port`. Run `./install.sh -o preflight` to check every node before you install.                                                          |
| Install fails with `ClusterRole "aigent-ds-role" ... exists and cannot be imported` | An agent set is already installed in this cluster, in another namespace. Upgrade that one instead, or install the second set with `--release-suffix` as above.                                                                                                                                                                                                            |
| Some workloads' logs are missing                                                    | Make sure the containers write to stdout/stderr, and that their streams are assigned to the workspace you're looking in.                                                                                                                                                                                                                                                  |
| No metrics after turning on **Collect Prometheus metrics**                          | Re-run the install command: the switch only takes effect once the agent has the access it needs. See [Collecting metrics](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/metrics/collecting.md).                                                                                                                                                   |
| Pods' OTLP traces never show up                                                     | Traces need agent v1.4.0 or later (re-run the install command to upgrade) and a plan that includes Traces. See [Sending traces](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/traces/sending-traces.md#troubleshooting).                                                                                                                          |

### Tips

* Install a separate Kubernetes source per cluster rather than sharing tokens across clusters.
* Prefer the agent's Service over host ports for sending OTLP from pods. It works with `--no-host-port` too.
* Get the current install command any time with `dstl8 sources install-script <source>`, or from the source's **Install Script** action.
* Assign the resulting streams to workspaces as described in [Assigning streams to workspaces](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources.md#assigning-streams-to-workspaces).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources/kubernetes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
