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

# Kubernetes

> Read pod logs, events, and metrics directly from a cluster API server.

Connect Kubernetes so Struct Agent can read pod logs, events and metrics from the intended cluster. Verify the API endpoint and the requested read access.

## Inspect access and existing connections

Use a claimed workspace with permission to configure connections.

```bash theme={null}
struct whoami --json
struct connections catalog kubernetes --json
struct connections list --json
```

Use the catalog's current fields, choices and permission requirements. Reuse an existing healthy connection instead of creating a duplicate.

## Connect with the CLI

Supply credentials from approved secret storage through `K8S_TOKEN`, `KUBECONFIG_YAML`. The catalog describes which are needed for the selected authentication method. Do not put literal secrets in shell arguments or chat.

Print the setup material first:

```bash theme={null}
struct connect kubernetes --print-commands
```

An authorized operator runs the generated provider commands after checking the account and scope. Printing them does not apply grants. Preserve generated identifiers (such as an AWS External ID or Snowflake key-pair ID), then run the returned connection command with the real values.

Use a ServiceAccount token or kubeconfig with static credentials. For a self-signed cluster, supply its CA certificate through the catalog's file input. On GKE DNS endpoints, the cluster must permit Kubernetes tokens through DNS; otherwise the connection returns `credentials_rejected`. Check reachability as well as RBAC.

## Verify and recover

Use the returned connection ID:

```bash theme={null}
struct connections show CONNECTION_ID --json
struct connections test CONNECTION_ID --json
```

Inspect `ok`, `health` and missing permissions, not only the exit code. `struct connections grant-command CONNECTION_ID` prints repair instructions where supported; have an authorized operator apply them. For expired OAuth links, start the connection command again and use the new link. Do not reconnect to a different account silently.

Verify a bounded operation for the requested job. Connection health proves checked access; it does not prove telemetry arrival, an investigation or alert delivery.

## What Struct reads

Pod logs, Kubernetes events such as restarts and OOM kills, and pod status by namespace. Pod CPU and memory also need [Metrics Server](https://github.com/kubernetes-sigs/metrics-server) in the cluster; without it, the metrics tool returns `available: false` with a reason.

## Permissions

The ServiceAccount token needs get, list and watch on pods, pods/log, namespaces and events, plus get and list on pod metrics (metrics.k8s.io) for pod CPU and memory. The setup command grants both.

### Pods, logs and events

Read pod logs, Kubernetes events such as restarts and OOM kills, and pod status by namespace.

Granted by: `ClusterRole log-reader`.

| Resource | Used for |
| - | - |
| `pods` | get, list, watch |
| `pods/log` | get, list, watch |
| `namespaces` | get, list, watch |
| `events` | get, list, watch |

### Pod metrics

Read pod CPU and memory from the metrics API. Only needed if you want pod metrics; without it, they show as unavailable.

| Resource | Used for |
| - | - |
| **pods in the metrics.k8s.io API group** (`metrics.k8s.io/pods`) | get, list |

### How to grant

> [accordion] Create a read-only ServiceAccount
>
> ```bash theme={null}
> kubectl create serviceaccount log-reader -n default
>
> kubectl apply -f - <<'YAML'
> apiVersion: rbac.authorization.k8s.io/v1
> kind: ClusterRole
> metadata:
>   name: log-reader
> rules:
>   - apiGroups: [""]
>     resources: ["pods", "pods/log", "namespaces", "events"]
>     verbs: ["get", "list", "watch"]
>   - apiGroups: ["metrics.k8s.io"]
>     resources: ["pods"]
>     verbs: ["get", "list"]
> ---
> apiVersion: rbac.authorization.k8s.io/v1
> kind: ClusterRoleBinding
> metadata:
>   name: log-reader-binding
> subjects:
>   - kind: ServiceAccount
>     name: log-reader
>     namespace: default
> roleRef:
>   kind: ClusterRole
>   name: log-reader
>   apiGroup: rbac.authorization.k8s.io
> YAML
>
> kubectl apply -f - <<'YAML'
> apiVersion: v1
> kind: Secret
> metadata:
>   name: log-reader-token
>   namespace: default
>   annotations:
>     kubernetes.io/service-account.name: log-reader
> type: kubernetes.io/service-account-token
> YAML
>
> # The token to paste into Struct
> kubectl get secret log-reader-token -n default -o jsonpath='{.data.token}' | base64 -d
> ```

Permission catalog version `2026-11-04.1`. See [permission changes](https://docs.struct.ai/reference/permission-changes.md).


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