How lazydeveloper9/kuber works
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 Workflow Composer · state.py Incident State · observe.py Observe Cluster · diagnose.py Diagnose Incident
Components 19
Incident Pipeline
Shared state flows through deterministic response stages.
- Continuous Agent Runner · Polls every 30 seconds.
run_agent.py - Workflow Composer
agent.py - Incident State · Principal boundary between pipeline stages.
core/state.py - Observe Cluster · Collects Pods, Events, and Nodes across namespaces.
core/observe.py - Detect Anomalies · Identifies CrashLoopBackOff, OOMKilled, and BackOff signals.
core/detect.py - Diagnose Incident · Retrieves focused container logs and evidence.
core/diagnose.py - Generate Remediation Plan · Requires structured JSON plans.
core/plan.py
Safety & Cluster Control
Approval and RBAC constrain remediation.
- Execute Approved Plan · Translates approved plans into kubectl operations.
core/execute.py - Kubernetes Cluster
- Custom ClusterRole · Enforcement boundary for allowed cluster actions.
manifests/rbac.yaml - Human Approval · Required for high-risk remediation.
- CrashLoop Demo Workload · Deliberately failing workload for pipeline exercises.
manifests/crashloop.yaml
Audit & Attestation
Local evidence is retained independently of the response loop.
- Explain & Record · Writes rationale and action history.
core/explain.py - Audit Log
audit_log.json - Hash-Chain Side Log
audit_side_db.jsonl - Action Audit Contract · Extensibility point, outside the core response loop.
contracts/ActionAudit.sol
Other components
- Local Ollama Llama · Keeps incident context air-gapped.
- API and Web UI · Separate UI/API surface.
server.py - Demo Reset · Provisions the failing demo workload.
reset_demo.py
Connections 24
- 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