# kubectl-ate CLI Reference

> Manage atespaces, actor templates, actors, snapshots, egress policies, and logs with the kubectl-ate plugin.

A Kubernetes-native CLI plugin for managing Substrate Actor and Worker lifecycles.

## Running the CLI

There are two ways to run the tool, depending on whether you are developing locally or installing it permanently.

### 1. Install as a native `kubectl` Plugin
You can use `go install` to compile the tool and place the binary directly into your Go bin directory (which should be in your `$PATH`). Because the source folder is named `kubectl-ate`, Kubernetes will automatically recognize the resulting binary!

```bash
go install ./cmd/kubectl-ate
```
You can now run it seamlessly anywhere as a native Kubernetes command: `kubectl ate <command>`.

### 2. Run directly from source (Development)
If you are testing changes to the codebase, you can bypass compilation and run the CLI directly from the source tree:

```bash
go run ./cmd/kubectl-ate <command>
```

## Connection & Auto Port-Forwarding
By default, `kubectl-ate` will automatically read your `~/.kube/config`, discover the `ate-api-server` pods in your cluster, and establish a temporary background port-forward tunnel to execute gRPC calls securely.

If you prefer to route traffic directly (e.g., from a pod in a namespace labeled `ate.dev/api-access=true`), simply provide the `--endpoint` flag to bypass the tunnel. Either way, `kubectl-ate` reads the CA that verifies `ate-api-server` from the cluster, so it needs a kubeconfig or in-cluster config.

For which credential to pass with `--token-file`, see the [Authentication Guide](https://ate.dev/docs/guides/authentication/index.md#people-running-kubectl-ate).

## Tracing
The CLI supports on-demand tracing using the `--trace` flag. When enabled, the CLI will generate a trace ID and signal to the server that it wants the request to be traced.

**Local (kind):**

The kind overlay installed by `ate-setup --kind deploy ate-system` already provisions an in-cluster OpenTelemetry Collector and Jaeger in the `otel-system` namespace. No additional setup is required.

Port-forward the Jaeger UI and invoke any command with `--trace`:
```bash
kubectl port-forward -n otel-system svc/jaeger 16686:16686 &
kubectl ate get actor my-counter-1 --trace
# open http://localhost:16686 and search for the most recent trace
```

## Global Flags
These flags can be appended to any command:

| Flag | Short | Description | Default |
|---|---|---|---|
| `--kubeconfig` | | Path to your kubeconfig file | `~/.kube/config` |
| `--context` | | Name of the kubeconfig context to use | current context |
| `--endpoint` | | Manual gRPC endpoint override (e.g., `localhost:8080`) | |
| `--token-file` | | Path to a bearer token for ate-api authentication, or `-` for stdin | a token for the shared `ate-client` ServiceAccount |
| `--output` | `-o` | Output format (`table`, `json`, `yaml`) | `table` |
| `--preview` | | Allow the use of preview features enabled on the server | `false` |
| `--trace` | | Enable on-demand tracing for the request | `false` |
| `--verbose` | `-v` | Increase output verbosity; may be repeated or stacked (e.g., `-v`, `-vv`, `-vvvvv`) | `0` |

Pass `--version` (`kubectl ate --version`) to print the CLI version and exit.

---

## Command Reference & Examples

### Getting Resources
List and inspect the state of actors and workers across the cluster.

```bash
# List actors in one atespace; -a is shorthand for --atespace
kubectl ate get actors --atespace <atespace>
kubectl ate get actors -a <atespace>

# List actors across all atespaces
kubectl ate get actors -A

# Get a specific actor by name and output as raw YAML
kubectl ate get actor <actor-name> --atespace <atespace> -o yaml

# List all physical workers or get specific workers by name
kubectl ate get workers
kubectl ate get worker <worker-name>

# Filter workers by Kubernetes namespace, assigned-actor atespace,
# worker pool labels, or sandbox class (same flags as `top workers`)
kubectl ate get workers -n <namespace>
kubectl ate get workers -a <atespace>
kubectl ate get workers -l <label-selector>
kubectl ate get workers --sandbox-class <gvisor|microvm>

# Show live CPU and memory usage of worker pods
kubectl ate top workers
```

> **Note:** `get actors` requires either `--atespace <name>` / `-a <name>` (one atespace) or `-A`/`--all-atespaces` (all atespaces) — there is no default atespace. Getting a single actor always requires `--atespace`/`-a`, since an actor is addressed by `(atespace, name)`. `-a` (lower-case) scopes to one atespace; `-A` (upper-case) spans all.

> **Note:** Actors, workers, and actor templates are not Kubernetes CRDs — they live in the Substrate control plane's PostgreSQL database, not `etcd`. `kubectl get actor`, `kubectl get worker`, and `kubectl get actortemplate` will not return anything; only `kubectl ate get …` queries the control plane (see [Actor Templates](#actor-templates)). `kubectl get workerpool` *does* work, because pools are CRDs.

#### `kubectl ate get actor` output columns

| Column | Meaning |
|---|---|
| `ATESPACE` | The atespace the actor belongs to. Part of the actor's identity; folded into the storage key as `actor:<atespace>:<name>`. |
| `NAME` | The actor's name. User-provided for application actors; UUID for the golden actor that each template materialises while building its golden tag. |
| `TEMPLATE` | The `ActorTemplate` the actor references, displayed as `<atespace>/<name>`. |
| `STATE` | Current lifecycle state (`ACTOR_STATE_RESUMING`, `ACTOR_STATE_RUNNING`, `ACTOR_STATE_SUSPENDING`, `ACTOR_STATE_SUSPENDED`, `ACTOR_STATE_CRASHED`, `ACTOR_STATE_DELETING`, `ACTOR_STATE_REVERTING`). |
| `WORKER POD` | The worker pod (`<namespace>/<name>`) currently hosting the actor, or `<none>` while suspended. |
| `WORKER IPS` | Comma-separated pod IPs of that worker. Empty while suspended. |
| `VERSION` | Monotonic integer that increments on every state transition (resume / suspend / checkpoint). Useful for distinguishing snapshots. |
| `AGE` | Time elapsed since the actor was created. |

#### `kubectl ate get worker` output columns

| Column | Meaning |
|---|---|
| `NAME` | The worker's name. The control plane assigns it. Treat it as opaque. |
| `POOL` | The `WorkerPool` name. |
| `STATE` | Current worker state. `WORKER_STATE_ACTIVE` when schedulable. `WORKER_STATE_UNAVAILABLE` while the worker is not ready or is restarting. `WORKER_STATE_DRAINING` once the pod is terminating. |
| `ACTORS` | Actors assigned to the worker vs. the worker's actor limit (`<allocated>/<capacity>`). |
| `CPU(MILLICORES)` | Allocated vs. capacity CPU in millicores (`<allocated>/<capacity>`). Allocated includes each runtime's per-actor overhead. `-` if the worker reports no CPU capacity. |
| `MEMORY` | Allocated vs. capacity memory with binary suffixes, such as `0/960Mi`. Allocated includes each runtime's per-actor overhead. `-` if the worker reports no memory capacity. |
| `POD` | The worker pod (`<namespace>/<name>`). |
| `AGE` | Time elapsed since `ate-controller` created the Worker for its pod. |

### Atespaces

An **atespace** is the isolation boundary an actor belongs to. It must exist before you can create actors in it.

```bash
# Create an atespace
kubectl ate create atespace <atespace>

# List all atespaces
kubectl ate get atespaces

# Get an atespace
kubectl ate get atespace <atespace>

# Delete an atespace (must be empty: fails if any actors, templates, or tags remain)
kubectl ate delete atespace <atespace>
```

> **Note:** `create actor … -a <atespace>` requires the atespace to already exist, otherwise it fails with `FailedPrecondition`. `delete atespace` only removes an **empty** atespace. Delete its actors, actor templates, and tags first (cascade delete is not yet supported).

#### `kubectl ate get atespace` output columns

| Column | Meaning |
|---|---|
| `NAME` | The atespace name. Globally unique — atespaces are global-scoped. |
| `AGE` | Time elapsed since the atespace was created. |

### Actor Templates

An **actor template** describes what an actor runs: containers, volumes,
snapshot policy, and worker selection. Templates live in an
atespace and are immutable — there is no update; delete and recreate to change
one (or create a new template and repoint suspended actors to it with
`kubectl ate update actor --template`).

```bash
# Create a template from a manifest (protojson-shaped ateapi.ActorTemplate,
# a single YAML/JSON document; use -f - for stdin). The metadata's atespace
# must already exist.
kubectl ate create actor-template -f template.yaml

# List templates, or get one (also: -o yaml prints the re-applyable manifest).
kubectl ate get actor-templates -a <atespace>
kubectl ate get actor-template <name> -a <atespace> -o yaml

# Delete a template. This also deletes its golden actor and golden snapshot.
kubectl ate delete actor-template <name> -a <atespace>
```

See
[`demos/counter/counter-template.yaml.tmpl`](https://github.com/agent-substrate/substrate/blob/main/demos/counter/counter-template.yaml.tmpl)
for a complete manifest example.

#### `kubectl ate get actor-templates` output columns

| Column | Meaning |
|---|---|
| `ATESPACE` | The atespace the template belongs to. |
| `NAME` | The template's name. |
| `GOLDEN TAG` | The golden tag's name once it exists; `DISABLED` when the template opts out of golden snapshot creation; empty while the golden build is still running. |
| `ERROR` | `ERROR` when the golden build failed; `-o yaml` shows the full message. |
| `AGE` | Time elapsed since the template was created. |

### Actor Lifecycle
Manage the execution state of your workloads.
*(Note: Actors are identified by a user-provided name, which must be a valid DNS-1123 label)*

```bash
# Create a new actor from an ActorTemplate.
kubectl ate create actor my-actor --template=<template-name> -a <atespace>

# Update an actor's template (requires the actor to be SUSPENDED) or worker selector.
kubectl ate update actor my-actor --template=<new-template-name> -a <atespace>
kubectl ate update actor my-actor --worker-selector=tier=paid,env=prod -a <atespace>
kubectl ate update actor my-actor --worker-selector="" -a <atespace>

# Resume an actor (assigns it to a free worker and restores its state)
kubectl ate resume actor my-actor -a <atespace>

# Suspend an actor (snapshots its state and frees the worker). By default the
# snapshot stays on the worker's node and is uploaded to storage in the background.
kubectl ate suspend actor my-actor -a <atespace>

# Suspend an actor and wait for its snapshot to reach storage.
kubectl ate suspend actor my-actor -a <atespace> --mode=sync

# Revert an actor to its last external snapshot (discards live or crashed state, or suspended state with a node-local snapshot, and returns to SUSPENDED)
# A suspended actor without a node-local snapshot is already at its external snapshot, so it cannot be reverted
kubectl ate revert actor my-actor -a <atespace>

# Delete an actor, terminating workloads and detaching volumes.
kubectl ate delete actor my-actor -a <atespace>
```

### Sending Requests to an Actor

`proxy actor` forwards one or more local TCP ports to an actor. It presents
the client certificate for `spiffe://cluster.local/ns/ate-system/sa/atenet-client`, so the install must list that ID in
`--ingress-allowed-spiffe-ids`.

```bash
# Forward 127.0.0.1:8000 to actor port 80 (default when no ports are given).
kubectl ate proxy actor my-actor -a <atespace>
curl http://127.0.0.1:8000/

# Forward specific [local-port:]remote-port mappings.
kubectl ate proxy actor my-actor 8000:80 9090:9090 -a <atespace>
```

### Actor Snapshots

Suspending an actor creates a durable snapshot. Tags give snapshots stable,
Atespace-owned names; published tags may be used from other Atespaces. A tag is
created from a suspended actor and gets its own copy of that actor's snapshot,
so suspending or deleting the actor afterwards cannot collect it.

```bash
# List an Atespace's tags, all Atespaces' tags, or resolve tags by name.
kubectl ate get tags -a <atespace>
kubectl ate get tags -A
kubectl ate get tag <tag-name> [<tag-name> ...] -a <atespace>

# Tag the snapshot a suspended actor holds, then publish or unpublish the tag.
# After an asynchronous suspend, create tag uploads the local snapshot first if needed.
kubectl ate create tag <tag-name> -a <atespace> --actor <actor-name> [--scope published]
kubectl ate update tag <tag-name> -a <atespace> --scope published
kubectl ate update tag <tag-name> -a <atespace> --scope atespace

# Create an actor from a tag.
kubectl ate create actor <actor-name> -a <atespace> --template <template-name> --tag <tag-name>
kubectl ate delete tag <tag-name> -a <atespace>
```

### Egress Policies

An actor has at most one egress policy. See [Egress Traffic](https://ate.dev/docs/guides/egress-traffic/index.md), [Network Egress](https://ate.dev/docs/guides/network-egress/index.md), [MITM Trust Bundle](https://ate.dev/docs/guides/egress-trust-bundle/index.md), and [Egress Credential Injection](https://ate.dev/docs/guides/egress-credential-injection/index.md) for how outbound traffic is mediated and how rules are evaluated.

Example `policy.yaml`:

```yaml
rules:
  - https:
      hostnames: ["api.anthropic.com", "api.openai.com"]
      ports:
        numbers: [443]
```

```bash
# Get an actor's egress policy.
kubectl ate get egress-policy <actor-name> -a <atespace>
kubectl ate get egress-policy <actor-name> -a <atespace> -o yaml

# Create an egress policy.
kubectl ate create egress-policy <actor-name> -a <atespace> -f policy.yaml

# Copy the egress policy of another actor.
kubectl ate get egress-policy <src-actor> -a <atespace> -o yaml | \
  kubectl ate create egress-policy <actor-name> -a <atespace> -f -

# Replace an actor's egress policy: dump it, edit the rules, send it back.
kubectl ate get egress-policy <actor-name> -a <atespace> -o yaml > policy.yaml
$EDITOR policy.yaml
kubectl ate update egress-policy <actor-name> -a <atespace> -f policy.yaml

# Delete an actor's egress policy; the actor keeps running with all egress denied.
kubectl ate delete egress-policy <actor-name> -a <atespace>

# Delete it only if it is still the policy you read.
kubectl ate delete egress-policy <actor-name> -a <atespace> --uid <uid> --version <n>
```

#### Details

* `create` can take a manifest with no `metadata`, taking `name` and `atespace` from the command line.
* `update` replaces the entire policy and the manifest metadata must match `uid`
  and `version` for the `EgressPolicy` being updated.
* `delete` with the optional `--uid` and `--version` flags removes the policy only if
  the given values still match what `get -o yaml` reported; the server answers `Aborted` otherwise.

#### `kubectl ate get egress-policy` output columns

| Column | Meaning |
|---|---|
| `ATESPACE` | The atespace the actor and its policy belong to. |
| `ACTOR` | The actor the policy applies to. |
| `RULES` | Number of rules; `-o yaml` shows them in evaluation order. |
| `VERSION` | The policy's version, bumped on every update. |
| `AGE` | Time elapsed since the policy was created. |

### Logs

`kubectl ate logs` requires a resource-type subcommand. The only supported resource type is `actor`:

```bash
# Print the logs an actor has produced on its current worker.
# -a/--atespace is required, since an actor is addressed by (atespace, name).
kubectl ate logs actor my-actor -a <atespace>

# Follow the logs with -f. The stream is aggregated across worker
# reassignments, so the same actor stays queryable as it teleports between pods.
kubectl ate logs actor my-actor -a <atespace> -f

# Show only one container's logs with -c/--container.
kubectl ate logs actor my-actor -a <atespace> -c my-container

# Pick a class of lines with --source: containers (every container's output,
# no lifecycle events) or lifecycle (only the actor's lifecycle events).
kubectl ate logs actor my-actor -a <atespace> --source=lifecycle
```

Logs are streamable only while the actor is bound to a worker (i.e., `ACTOR_STATE_RUNNING`). For history across worker migrations, route through a centralized log backend (Loki, Elasticsearch, etc.); see the [Observability Guide](https://ate.dev/docs/guides/observability/index.md).

### Administration & Setup
Commands for bootstrapping the Substrate control plane.

```bash
# Generate a new Actor ID CA pool and push it directly to a Kubernetes Secret
kubectl ate admin make-ca-pool \
  --name actor-id-ca-pool \
  --secret-namespace ate-system \
  --ca-id "1"

# Generate a new JWT authority pool and push it to a Kubernetes Secret. The
# key is ES256 (--alg RS256, a 4096-bit RSA key, for relying parties that don't
# support ES256) and its ID defaults to the base64url SHA-256 of the public
# key's PKIX encoding (--key-id to override). The Secret holds the pool under
# "pool".
kubectl ate admin make-jwt-pool \
  --name actor-id-jwt-pool \
  --secret-namespace ate-system

# Rotate the JWT signing key. The new key is published but signs nothing until
# activated; activate it once relying parties have refetched the key set, and
# remove the old key once every token it signed has expired. list-jwt-keys
# shows each key's ID and algorithm and marks the active one.
kubectl ate admin list-jwt-keys --name actor-id-jwt-pool --secret-namespace ate-system
kubectl ate admin add-jwt-key --name actor-id-jwt-pool --secret-namespace ate-system
kubectl ate admin activate-jwt-key --name actor-id-jwt-pool --secret-namespace ate-system --key-id <new key ID>
kubectl ate admin remove-jwt-key --name actor-id-jwt-pool --secret-namespace ate-system --key-id <old key ID>
```
