# lazydeveloper9/kuber architecture

> Architecture diagram of the GitHub repository lazydeveloper9/kuber, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lazydeveloper9/kuber
- Repository: https://github.com/lazydeveloper9/kuber

## Overview

#### Purpose and Entry Points
K8sWhisperer is an air-gapped Python SRE agent for detecting and remediating Kubernetes incidents with a locally hosted Ollama Llama model. Its primary continuous entry point is `run_agent.py`; stage-specific runners support isolated execution (`run_detect.py`, `run_diagnose.py`, `run_plan.py`). `agent.py` likely composes the workflow, while `server.py` and `frontend/index.html` provide a separate UI/API surface.

#### Stateful Incident Pipeline
The core system is a deterministic six-stage incident workflow, with shared typed state defined in `core/state.py`:
1. observe cluster resources,
2. detect distressed workloads,
3. diagnose with logs,
4. produce an LLM remediation plan,
5. safety-gated execution,
6. audit/explanation.

The state object is the principal boundary between stages, enabling each stage to enrich an incident rather than directly coupling to Kubernetes, the LLM, or execution.

Paths: `core/state.py`, `agent.py`, `run_agent.py`.

#### Kubernetes Observation and Detection
Observation polls Kubernetes across namespaces and converts Pods, Events, and Node data into the internal state graph. Detection applies deterministic anomaly logic for signals such as CrashLoopBackOff, OOMKilled, and BackOff events; it should narrow the set of resources sent to subsequent diagnostic and LLM stages.

Paths: `core/observe.py`, `core/detect.py`, `run_obseve.py`.

#### Diagnosis and Local AI Planning
Diagnosis retrieves focused container logs and derives likely root-cause evidence. Planning passes structured incident context to the locally running Ollama model, expecting a JSON-formatted remediation plan rather than free-form command execution. This is the key intelligence boundary: cluster data remains local, and the model does not directly control Kubernetes.

Paths: `core/diagnose.py`, `core/plan.py`, `core/explain.py`.

#### Controlled Remediation Boundary
Execution translates an approved remediation plan into constrained `kubectl` operations. Human approval is required for high-risk actions such as pod deletion or deployment patching. Kubernetes RBAC is the enforcement layer: even an invalid or malicious plan is limited by the service account’s custom ClusterRole rather than application logic alone.

Paths: `core/execute.py`, `manifests/rbac.yaml`, `manifests/crashloop.yaml`.

#### Audit, Integrity, and Compliance
The agent writes remediation rationale and action history to a persistent local audit log. Repository artifacts indicate a hash-chain/side-log model, with README-described Stellar Testnet anchoring, receipt verification, re-anchoring, and compliance evidence. A Solidity contract is included as an extensibility point for future on-chain attestation or policy governance, not part of the core Kubernetes response loop.

Paths: `core/explain.py`, `audit_log.json`, `audit_side_db.jsonl`, `contracts/ActionAudit.sol`.

#### Runtime and Operational Dependencies
The runtime requires Python, Kubernetes access through kubectl/client tooling, a local Minikube or equivalent cluster, and local Ollama running `llama3.2`; no cloud LLM API is intended. `reset_demo.py` provisions the deliberate failing workload used to exercise the pipeline, while `safe_start.py` supports environment recovery. The polling cadence is 30 seconds under the main agent loop.

Paths: `requirements.txt`, `reset_demo.py`, `safe_start.py`.

Main entry points: [`agent.py`](https://github.com/lazydeveloper9/kuber/blob/main/agent.py) (Workflow Composer), [`core/state.py`](https://github.com/lazydeveloper9/kuber/blob/main/core/state.py) (Incident State), [`core/observe.py`](https://github.com/lazydeveloper9/kuber/blob/main/core/observe.py) (Observe Cluster), [`core/diagnose.py`](https://github.com/lazydeveloper9/kuber/blob/main/core/diagnose.py) (Diagnose Incident)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Incident Pipeline"]
  node_main_runner["Continuous Agent Runner<br/>Python entry point<br/>[run_agent.py]"]
  node_agent["Workflow Composer<br/>Python orchestrator<br/>[agent.py]"]
  node_state["Incident State<br/>typed shared state<br/>[state.py]"]
  node_observe["Observe Cluster<br/>Kubernetes observation<br/>[observe.py]"]
  node_detect["Detect Anomalies<br/>deterministic detection<br/>[detect.py]"]
  node_diagnose["Diagnose Incident<br/>log diagnosis<br/>[diagnose.py]"]
  node_plan["Generate Remediation Plan<br/>LLM planning<br/>[plan.py]"]
end

subgraph group_control["Safety &amp; Cluster Control"]
  node_execute["Execute Approved Plan<br/>constrained remediation<br/>[execute.py]"]
  node_cluster{{"Kubernetes Cluster<br/>cluster runtime"}}
  node_rbac["Custom ClusterRole<br/>RBAC policy<br/>[rbac.yaml]"]
  node_approval(("Human Approval<br/>safety gate"))
  node_demo_workload["CrashLoop Demo Workload<br/>Kubernetes manifest<br/>[crashloop.yaml]"]
end

subgraph group_audit["Audit &amp; Attestation"]
  node_explain["Explain &amp; Record<br/>audit stage<br/>[explain.py]"]
  node_audit_log[("Audit Log<br/>persistent local log<br/>[audit_log.json]")]
  node_side_log[("Hash-Chain Side Log<br/>integrity evidence")]
  node_contract["Action Audit Contract<br/>future attestation<br/>[ActionAudit.sol]"]
end

node_ollama{{"Local Ollama Llama<br/>local model runtime"}}
node_api_ui["API and Web UI<br/>optional interface<br/>[server.py]"]
node_demo_reset["Demo Reset<br/>Python utility<br/>[reset_demo.py]"]

node_main_runner -->|"runs"| node_agent
node_agent -->|"creates and enriches"| node_state
node_agent -->|"invokes"| node_observe
node_observe -->|"polls"| node_cluster
node_observe -->|"resource graph"| node_state
node_agent -->|"invokes"| node_detect
node_detect -->|"distressed workloads"| node_state
node_agent -->|"invokes"| node_diagnose
node_diagnose -->|"retrieves logs"| node_cluster
node_diagnose -->|"root-cause evidence"| node_state
node_agent -->|"invokes"| node_plan
node_plan -->|"structured context"| node_ollama
node_plan -->|"JSON remediation plan"| node_state
node_state -->|"high-risk plan"| node_approval
node_approval -->|"authorizes"| node_execute
node_execute -->|"constrained kubectl actions"| node_cluster
node_rbac -->|"limits service account"| node_cluster
node_agent -->|"invokes"| node_explain
node_explain -->|"writes actions and rationale"| node_audit_log
node_explain -->|"writes integrity evidence"| node_side_log
node_side_log -.->|"future attestation"| node_contract
node_api_ui -.->|"separate control surface"| node_agent
node_demo_reset -->|"provisions"| node_demo_workload
node_demo_workload -->|"deployed to"| node_cluster

click node_main_runner "https://github.com/lazydeveloper9/kuber/blob/main/run_agent.py"
click node_agent "https://github.com/lazydeveloper9/kuber/blob/main/agent.py"
click node_state "https://github.com/lazydeveloper9/kuber/blob/main/core/state.py"
click node_observe "https://github.com/lazydeveloper9/kuber/blob/main/core/observe.py"
click node_detect "https://github.com/lazydeveloper9/kuber/blob/main/core/detect.py"
click node_diagnose "https://github.com/lazydeveloper9/kuber/blob/main/core/diagnose.py"
click node_plan "https://github.com/lazydeveloper9/kuber/blob/main/core/plan.py"
click node_execute "https://github.com/lazydeveloper9/kuber/blob/main/core/execute.py"
click node_explain "https://github.com/lazydeveloper9/kuber/blob/main/core/explain.py"
click node_rbac "https://github.com/lazydeveloper9/kuber/blob/main/manifests/rbac.yaml"
click node_audit_log "https://github.com/lazydeveloper9/kuber/blob/main/audit_log.json"
click node_side_log "https://github.com/lazydeveloper9/kuber/blob/main/audit_side_db.jsonl"
click node_contract "https://github.com/lazydeveloper9/kuber/blob/main/contracts/ActionAudit.sol"
click node_api_ui "https://github.com/lazydeveloper9/kuber/blob/main/server.py"
click node_demo_workload "https://github.com/lazydeveloper9/kuber/blob/main/manifests/crashloop.yaml"
click node_demo_reset "https://github.com/lazydeveloper9/kuber/blob/main/reset_demo.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main_runner,node_agent,node_state,node_observe,node_detect,node_diagnose,node_plan toneBlue
class node_execute,node_cluster,node_rbac,node_approval,node_demo_workload toneAmber
class node_explain,node_audit_log,node_side_log,node_contract toneMint
class node_ollama,node_api_ui,node_demo_reset toneNeutral
```

## Components

### Incident Pipeline

Shared state flows through deterministic response stages.

- [Continuous Agent Runner](https://github.com/lazydeveloper9/kuber/blob/main/run_agent.py): Python entry point · Polls every 30 seconds. · `run_agent.py`
- [Workflow Composer](https://github.com/lazydeveloper9/kuber/blob/main/agent.py): Python orchestrator · `agent.py`
- [Incident State](https://github.com/lazydeveloper9/kuber/blob/main/core/state.py): typed shared state · Principal boundary between pipeline stages. · `core/state.py`
- [Observe Cluster](https://github.com/lazydeveloper9/kuber/blob/main/core/observe.py): Kubernetes observation · Collects Pods, Events, and Nodes across namespaces. · `core/observe.py`
- [Detect Anomalies](https://github.com/lazydeveloper9/kuber/blob/main/core/detect.py): deterministic detection · Identifies CrashLoopBackOff, OOMKilled, and BackOff signals. · `core/detect.py`
- [Diagnose Incident](https://github.com/lazydeveloper9/kuber/blob/main/core/diagnose.py): log diagnosis · Retrieves focused container logs and evidence. · `core/diagnose.py`
- [Generate Remediation Plan](https://github.com/lazydeveloper9/kuber/blob/main/core/plan.py): LLM planning · Requires structured JSON plans. · `core/plan.py`

### Safety & Cluster Control

Approval and RBAC constrain remediation.

- [Execute Approved Plan](https://github.com/lazydeveloper9/kuber/blob/main/core/execute.py): constrained remediation · Translates approved plans into kubectl operations. · `core/execute.py`
- **Kubernetes Cluster**: cluster runtime
- [Custom ClusterRole](https://github.com/lazydeveloper9/kuber/blob/main/manifests/rbac.yaml): RBAC policy · Enforcement boundary for allowed cluster actions. · `manifests/rbac.yaml`
- **Human Approval**: safety gate · Required for high-risk remediation.
- [CrashLoop Demo Workload](https://github.com/lazydeveloper9/kuber/blob/main/manifests/crashloop.yaml): Kubernetes manifest · Deliberately failing workload for pipeline exercises. · `manifests/crashloop.yaml`

### Audit & Attestation

Local evidence is retained independently of the response loop.

- [Explain & Record](https://github.com/lazydeveloper9/kuber/blob/main/core/explain.py): audit stage · Writes rationale and action history. · `core/explain.py`
- [Audit Log](https://github.com/lazydeveloper9/kuber/blob/main/audit_log.json): persistent local log · `audit_log.json`
- [Hash-Chain Side Log](https://github.com/lazydeveloper9/kuber/blob/main/audit_side_db.jsonl): integrity evidence · `audit_side_db.jsonl`
- [Action Audit Contract](https://github.com/lazydeveloper9/kuber/blob/main/contracts/ActionAudit.sol): future attestation · Extensibility point, outside the core response loop. · `contracts/ActionAudit.sol`

### Other components

- **Local Ollama Llama**: local model runtime · Keeps incident context air-gapped.
- [API and Web UI](https://github.com/lazydeveloper9/kuber/blob/main/server.py): optional interface · Separate UI/API surface. · `server.py`
- [Demo Reset](https://github.com/lazydeveloper9/kuber/blob/main/reset_demo.py): Python utility · Provisions the failing demo workload. · `reset_demo.py`

## Connections

- Continuous Agent Runner → Workflow Composer: runs
- Workflow Composer → Incident State: creates and enriches
- Workflow Composer → Observe Cluster: invokes
- Observe Cluster → Kubernetes Cluster: polls
- Observe Cluster → Incident State: resource graph
- Workflow Composer → Detect Anomalies: invokes
- Detect Anomalies → Incident State: distressed workloads
- Workflow Composer → Diagnose Incident: invokes
- Diagnose Incident → Kubernetes Cluster: retrieves logs
- Diagnose Incident → Incident State: root-cause evidence
- Workflow Composer → Generate Remediation Plan: invokes
- Generate Remediation Plan → Local Ollama Llama: structured context
- Generate Remediation Plan → Incident State: JSON remediation plan
- Incident State → Human Approval: high-risk plan
- Human Approval → Execute Approved Plan: authorizes
- Execute Approved Plan → Kubernetes Cluster: constrained kubectl actions
- Custom ClusterRole → Kubernetes Cluster: limits service account
- Workflow Composer → Explain & Record: invokes
- Explain & Record → Audit Log: writes actions and rationale
- Explain & Record → Hash-Chain Side Log: writes integrity evidence
- Hash-Chain Side Log → Action Audit Contract: future attestation
- API and Web UI → Workflow Composer: separate control surface
- Demo Reset → CrashLoop Demo Workload: provisions
- CrashLoop Demo Workload → Kubernetes Cluster: deployed to
