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

# Kubernetes

> Connect any Kubernetes cluster via kubeconfig so OpenSRE can investigate pods, deployments, and events

OpenSRE connects to Kubernetes using a standard kubeconfig. Works with any cluster — GKE, AKS, EKS, on-prem, kind, or minikube — without requiring AWS credentials or cloud-specific tooling.

## Prerequisites

* A kubeconfig file (typically `~/.kube/config`) or its raw YAML content
* Read access to the namespaces you want to investigate (`get`/`list` on pods, deployments, events, logs)

## Setup

### Option 1: Interactive CLI

```bash theme={null}
opensre integrations setup kubernetes
```

The wizard will ask for:

1. **kubeconfig** — paste the raw kubeconfig YAML, or provide a file path that will be read and stored inline
2. **Context** — optional; leave blank to use the kubeconfig's current context
3. **Default namespace** — defaults to `default`

### Option 2: Environment variables

```bash theme={null}
# Point to a kubeconfig file
KUBECONFIG=/home/user/.kube/config

# Or provide the raw YAML directly (useful in CI / Docker)
KUBECONFIG_CONTENT="$(cat ~/.kube/config)"

# Optional overrides
KUBECONFIG_CONTEXT=my-context
KUBECONFIG_NAMESPACE=production
```

### Option 3: Verify connectivity

```bash theme={null}
opensre verify kubernetes
```

A successful verification lists the namespaces visible to the configured credentials.

## Available tools

| Tool                           | What it does                                                                                                                                            |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `kubernetes_list_pods`         | List pods in a namespace with phase, readiness, and restart counts                                                                                      |
| `kubernetes_get_pod_logs`      | Fetch recent log lines from a pod container                                                                                                             |
| `kubernetes_list_deployments`  | List deployments with desired/ready/available replica counts                                                                                            |
| `kubernetes_get_events`        | List cluster events — crash loops, OOM kills, scheduling failures                                                                                       |
| `kubernetes_describe_pod`      | Fetch full spec, status, and container states for a single pod                                                                                          |
| `kubernetes_list_nodes`        | List cluster nodes with conditions, capacity, and allocatable resources                                                                                 |
| `kubernetes_list_services`     | List services with their type, clusterIP, ports, and selector                                                                                           |
| `kubernetes_list_statefulsets` | List StatefulSets with desired/ready/current/updated replica counts                                                                                     |
| `kubernetes_list_daemonsets`   | List DaemonSets with desired/current/ready/available counts                                                                                             |
| `kubernetes_list_ingresses`    | List Ingress resources with routing rules, host→service path mappings, and TLS config                                                                   |
| `kubernetes_list_configmaps`   | List ConfigMaps with their key-value data                                                                                                               |
| `kubernetes_get_resource`      | Fetch a single named resource by type and name (pods, deployments, statefulsets, daemonsets, services, ingresses, configmaps, replicasets, pvcs, nodes) |

## Configuration reference

| Field        | Environment variable                           | Default         | Description                        |
| ------------ | ---------------------------------------------- | --------------- | ---------------------------------- |
| `kubeconfig` | `KUBECONFIG_CONTENT` or read from `KUBECONFIG` | —               | Raw kubeconfig YAML (required)     |
| `context`    | `KUBECONFIG_CONTEXT`                           | current context | Kubeconfig context to activate     |
| `namespace`  | `KUBECONFIG_NAMESPACE`                         | `default`       | Default namespace for tool queries |

## Example: investigating a crash-looping pod

```
> What's wrong with the payments-api pod in the production namespace?
```

OpenSRE will:

1. Call `kubernetes_list_pods` scoped to `production` to find pods with high restart counts
2. Call `kubernetes_get_pod_logs` to read recent container output
3. Call `kubernetes_get_events` with `involvedObject.name=payments-api` to surface Warning events
4. Correlate the evidence into a root-cause summary

## Permissions

The kubeconfig's service account or user needs these Kubernetes RBAC permissions:

```yaml theme={null}
rules:
  - apiGroups: [""]
    resources: ["pods", "pods/log", "events", "namespaces", "nodes", "services", "configmaps", "persistentvolumeclaims"]
    verbs: ["get", "list"]
  - apiGroups: ["apps"]
    resources: ["deployments", "statefulsets", "daemonsets", "replicasets"]
    verbs: ["get", "list"]
  - apiGroups: ["networking.k8s.io"]
    resources: ["ingresses"]
    verbs: ["get", "list"]
```
