Skip to content

feat(k8s): cluster deployment health diagnosis (devops k8s doctor) #408

Closed

Description

@dan-petty

Problem Statement

A review of live cluster logs surfaced failures that are individually obvious and collectively invisible, because nothing correlates them. A node left NotReady,SchedulingDisabled had metrics-server retrying it every 12 seconds: six restarts and a log filled entirely with one unreachable host. Meanwhile a PersistentVolume delete had been timing out for three days behind a helper pod stuck Terminating. Each is a one-line symptom; none is reported anywhere an operator looks.

What exists at release/v0.2.25 (9c879ae) reads the signals but correlates none of them:

  • devops k8s status (src/devops_cli/commands/k8s/cluster_context.py:117-135) prints a node table after a bare load_kube_config(), so it follows kubectl's current context rather than the configured one.
  • devops k8s pods (src/devops_cli/commands/k8s/diagnostics.py:36-56,84-125) prints the STATUS, READY and RESTARTS columns kubectl prints, computed by PodInfo.from_pod (src/devops_cli/models/k8s.py:334-369), which already derives CrashLoopBackOff, Terminating, Init:…, per-container last_termination_reason and an unhealthy flag. node_is_ready (models/k8s.py:97) reads a node's Ready condition.
  • The TUI reads nodes and every pod in one refresh with a client-side timeout (fetch_k8s_status, src/devops_cli/ui/data_providers.py:229-253) and a pod's events only when its inspector opens (fetch_pod_events, :261-275, matched by uid with CONST_K8S_POD_EVENT_FIELD_SELECTOR, src/devops_cli/config/constants.py:2304). That list_namespaced_event call is the only event read in the code base; nothing lists cluster-wide events. PodEventInfo (models/k8s.py:370) keeps type, reason, message, count and last-seen, not the involved object.
  • _get_unready_nodes (src/devops_cli/commands/k8s/cluster_runtime.py:172-198) shells out to kubectl get nodes -o json; its one caller is deploy-stack (stack_lifecycle.py:781), which uses it to skip Helm --wait on DaemonSet releases.
  • KubernetesService (src/devops_cli/k8s/service.py:227-302) lists nodes (cached) and pods and reads logs (tail bounded 1..10000), but none of those calls carries _request_timeout, and it has no event method.
  • The only "diagnosis" is the MCP prompt template k8s_diagnostics_prompt (src/devops_cli/ai/mcp/server.py:2837,2857; src/devops_cli/ai/tasks/k8s_diagnostics_prompt.md), three lines of instructions to a model.

No code path reads cluster-wide Warning events, no code path joins a pod's symptoms to the node it runs on, and nothing names a cause or a remediation. No doctor command exists (grep -rn doctor src/ is empty); the only references are docs/ROADMAP.md:1138, a note in the #646 task file, and this item's task file, which still says v0.2.24 and Backlog. No commit has delivered any part of this item.

Proposed Solution

Add devops k8s doctor: one read-only command that gathers nodes, pods, cluster-wide Warning events and, for the pods already flagged, a bounded tail of container logs, through the Kubernetes API only; evaluates a fixed, ordered rule table over them; and prints a ranked list of findings, each naming the resource, the likely cause, the evidence and the remediation. The rules attribute symptoms to their cause so a cluster fault absorbs the workload symptoms it explains: pods crash-looping on a NotReady or cordoned node appear under the node finding, not as separate workload findings.

The data source is the Kubernetes API and nothing else (decided 2026-10-02): no Prometheus query, no Loki query, no --since window. Every signal the issue names is available from list_node, the pod list, the Warning event list and read_namespaced_pod_log, so the command works on any cluster the CLI can reach, including the devcontainer's minikube, and its tests run offline on tests/k8s_fakes.py.

Shape of the change:

  • src/devops_cli/k8s/doctor.py: pure functions over SDK objects, read attribute by attribute as models/k8s.py reads them. collect(core, namespace, tail) makes list_node, list_pod_for_all_namespaces (or list_namespaced_pod under --namespace), list_event_for_all_namespaces(field_selector="type=Warning") (or the namespaced form) and, only for pods a rule has flagged, read_namespaced_pod_log(tail_lines=…); every call carries _request_timeout=DEFAULT_K8S_CONNECT_TIMEOUT_SECONDS (config/defaults.py:796) as fetch_k8s_status does. diagnose(snapshot) applies the rule table and returns a DoctorReport.
  • The CoreV1Api is built the way _get_k8s_client builds it (ui/data_providers.py:146-163): load_kube_config(context=resolve_context(context)) (src/devops_cli/k8s/context.py:78), never a bare load_kube_config(). KubernetesService is not used, because its list calls carry no timeout and it has no event method.
  • src/devops_cli/models/k8s.py: NodeInfo (name, ready via node_is_ready, unschedulable, the Ready condition's reason and message, pod count), ClusterEventInfo (what PodEventInfo keeps plus the involved object's kind, namespace, name and uid), Finding (rule id, severity critical|warning, class cluster|workload, resource kind/namespace/name, cause, evidence lines, remediation, affected resources) and DoctorReport (context, counts, findings, errors).
  • src/devops_cli/commands/k8s/diagnostics.py: doctor_cmd registered as app.command(name="doctor") in src/devops_cli/commands/k8s/__init__.py (the 30 registrations at :98-127). Options: --namespace/-n (default: all namespaces, since nodes and PV events are cluster-scoped), --context, --tail (log lines per flagged container, default DEFAULT_K8S_DOCTOR_LOG_TAIL_LINES = 200), --format/-f table|json|yaml through normalize_format and emit_serialized (src/devops_cli/output/serialization.py:71) as gpu-matrix does (commands/k8s/gpu_matrix.py:128-154), which is the join point the output-format roadmap item names (docs/ROADMAP.md:629-631), and --dry-run. Kubernetes imports stay inside the function as the other diagnostics.py commands keep theirs.
  • Exit code (decided 2026-10-02): 0 when the report has no findings, 2 when it has at least one finding, 1 when the kubeconfig cannot be loaded, the cluster cannot be reached or any list call fails. The code is the same for every --format, so a script can tell "unhealthy" from "could not look". With 1 the error is printed through mask_secrets and DoctorReport.errors names the call that failed.
  • Table output through print_table (src/devops_cli/output/console.py:616); an API error is passed through mask_secrets (src/devops_cli/security/sanitizer.py:269) as _build_pods_table does (diagnostics.py:52-55). Help strings in src/devops_cli/lang/en/help.py next to pods (:251).
  • An MCP tool k8s_doctor in src/devops_cli/ai/mcp/server.py beside k8s_status (:285-291), running uv run devops k8s doctor --format json through _run_mcp_cmd. Because _run_mcp_cmd prefixes every non-zero exit with Command exited with status N: (server.py:77-78,91-92), the tool's docstring states that status 2 means findings and the JSON report follows on the next line, and status 1 means the cluster could not be read.
  • docs/CLI_REFERENCE.md and docs/MCP_TOOLS.md regenerated with uv run devops docs generate (src/devops_cli/commands/docs.py:53,156; pinned by tests/test_docs.py:200-234).

The rule table, held as data, in evaluation order (cluster rules first; a resource claimed by an earlier rule is listed as affected by it, not re-reported):

id class trigger cause and remediation
node-not-ready cluster, critical Ready condition not True node unreachable or kubelet down; pods on it are affected; check the node, or drain it
node-cordoned cluster, warning spec.unschedulable with pods still scheduled on it, or with pending pods whose FailedScheduling event names it scheduling disabled; uncordon when maintenance ends
volume-reclaim-stuck cluster, critical Warning event reason VolumeFailedDelete on a PersistentVolume, or a local-path helper pod Terminating past DEFAULT_K8S_DOCTOR_STUCK_SECONDS provisioner cannot delete the volume; detection and reporting only, never deletion (the local-path reclaim item at docs/ROADMAP.md:626-628 owns remediation)
pod-stuck-terminating workload, warning deletion_timestamp older than DEFAULT_K8S_DOCTOR_STUCK_SECONDS (default 300) finalizer or node not responding; name the finalizers
pod-crashloop workload, critical container waiting CrashLoopBackOff, or last_termination_reason OOMKilled / Error with restarts above DEFAULT_K8S_DOCTOR_RESTART_THRESHOLD (default 3) evidence is the tail's error lines; OOMKilled names the memory limit
pod-image-pull workload, critical waiting reason ImagePullBackOff or ErrImagePull image, tag or registry credentials
pod-unschedulable workload, warning Pending with a FailedScheduling event the event message names the resource that is short
pod-not-ready workload, warning Running with READY short past DEFAULT_K8S_DOCTOR_STUCK_SECONDS of age readiness probe failing; evidence is the Unhealthy event
warning-events workload, warning a Warning event with count >= DEFAULT_K8S_DOCTOR_EVENT_COUNT_THRESHOLD (default 5) on a resource no other rule claimed reported with its reason and message
log-errors workload, evidence a flagged pod whose tail has an error-line share above DEFAULT_K8S_DOCTOR_LOG_ERROR_RATIO, matched by CONST_K8S_DOCTOR_LOG_ERROR_PATTERN corroborating evidence attached to the pod's finding, never a finding on its own

Ranking: cluster findings before workload findings, critical before warning, then by number of affected resources, then restarts, then name. A pod on a NotReady or cordoned node is attributed to the node finding whatever its own symptoms; that is the constraint the issue sets.

Scope

In scope: src/devops_cli/k8s/doctor.py; additions to src/devops_cli/models/k8s.py; doctor_cmd in src/devops_cli/commands/k8s/diagnostics.py and its registration in commands/k8s/__init__.py; help strings; the named defaults and the error pattern in config/defaults.py and config/constants.py; the k8s_doctor MCP tool; regenerated docs/CLI_REFERENCE.md and docs/MCP_TOOLS.md; tests/test_k8s_doctor.py; tests/k8s_fakes.py extended so FakeCoreV1 (:176-209, which today answers only list_pod_for_all_namespaces, list_node and list_namespaced_event) also records list_namespaced_pod, list_event_for_all_namespaces and read_namespaced_pod_log, and node() (:139) takes unschedulable; changelog.d/408.md; and docs/agent/tasks/task-408-cluster-deployment-health-diagnosis-devops-k8s-doctor.md rewritten as Done with the item's milestone (v0.2.27 today; whether it moves to v0.2.28 is decided at the v0.2.25 cut).

The command reads the Kubernetes API only. It writes nothing to the cluster.

Key Questions

  • Where does the data come from: the Kubernetes API only, or Prometheus and Loki too? Answered (owner decision, 2026-10-02): the Kubernetes API only. Every signal the issue names is there: node conditions and spec.unschedulable, container restart counts and waiting or last-termination reasons, Warning events, and container logs. It works on every cluster the CLI can reach, including the devcontainer's minikube, where no Prometheus is configured (PrometheusConfig.url defaults to None, src/devops_cli/config/settings.py:164-166). Tests build on tests/k8s_fakes.py and never touch the network. The alternatives are real but stay out: devops prometheus already queries /api/v1/query (src/devops_cli/commands/prometheus.py:146,200) and would add restart rate over a window (kube_pod_container_status_restarts_total, as k8s/monitoring/dashboards/sre-service.json:150 reads it); devops k8s logs --loki-url (commands/k8s/cluster_context.py:349-396, src/devops_cli/k8s/logql.py) would add an error rate over time, and the homelab chart ships cluster events and pod logs to Loki (k8s/monitoring/k8s-monitoring-values.yaml:72-78). Both are history the dashboards already show; a Prometheus-backed --since is a separate follow-up candidate if the API-only report proves too noisy. With this answer fix(k8s): pod logs reach loki once and labelled, with alloy as the only shipper (remove fluent-bit) #548 is not a dependency of this item.
  • What does the exit code say when findings exist? Answered (owner decision, 2026-10-02): 0 when the report has no findings, 2 when it has findings, 1 when the cluster cannot be reached or a list call fails. There is no single convention to inherit: k8s audit and gpu-matrix exit 1 for everything, while diff-helm treats 2 as success-with-differences (diagnostics.py:211-212) and scan and networking also use 2 (commands/scan.py:893, commands/k8s/networking.py:875). A distinct code lets a script tell "unhealthy" from "could not look". The mapping holds for every --format; the k8s_doctor MCP tool documents the Command exited with status 2: prefix _run_mcp_cmd adds (server.py:77-78,91-92) as "findings follow".
  • What is the ranking and cause model? Answered above: a fixed rule table evaluated in order with attribution, no model call. k8s_diagnostics_prompt stays as it is; an AI narrative over the report is a separate candidate.
  • Does "dashboard panel" mean the TUI Kubernetes tab or a Grafana dashboard? Answered for this item: neither. The owner's placement comment (2026-10-01) splits the command from the panel, so this item delivers the command and the panel becomes a follow-up candidate. For that candidate the TUI Kubernetes tab is the natural place, since it can call diagnose() on the snapshot fetch_k8s_status already holds (K8sSummary, ui/data_providers.py:44-62); a Grafana panel can only run PromQL, cannot reuse the rule table, and k8s-views-global.json already shows the raw signals ("Kubernetes Pods Status Reason", "Container Restarts by namespace").
  • JSON output: --json or --format? Answered: --format table|json|yaml through emit_serialized, the join point the output-format roadmap item names and that gpu-matrix in this command group already uses; chaos's bespoke --json + format_json (diagnostics.py:255,270) is the pattern that item retires.
  • How are logs kept bounded? Answered: logs are read only for pods a rule has already flagged, --tail lines per container (default 200), and are evidence, never a finding on their own.
  • How does a stuck PersistentVolume reach the report when the PV is cluster-scoped? Answered: list_event_for_all_namespaces(field_selector="type=Warning") returns events for cluster-scoped objects too (core/v1 writes them in the default namespace), and the rule matches involved_object.kind == "PersistentVolume" and reason VolumeFailedDelete. The helper pod stuck Terminating is joined by the PV name in the pod's volumes or in the event message.
  • Which cluster? Answered: the configured context through resolve_context(), overridable with --context, as the TUI does; devops k8s status's bare load_kube_config() is the behaviour the TUI docstring at ui/data_providers.py:146-158 calls out as wrong and is not copied.
  • Is any remediation applied? Answered: no. The command reports; it never deletes, uncordons or restarts anything. The local-path reclaim item (docs/ROADMAP.md:626-628) states the same constraint for volumes.

Acceptance Criteria

  • uv run devops k8s doctor --help lists --namespace, --context, --tail, --format and --dry-run; tests/test_k8s_doctor.py::test_doctor_is_registered_with_its_options runs it through CliRunner on devops_cli.commands.k8s.app and asserts the option names as one tuple.
  • The issue's first case is attributed to the node: with a fake node whose Ready condition is False and spec.unschedulable is True, a metrics-server pod on it with 6 restarts and CrashLoopBackOff, and a healthy pod on a healthy node, diagnose() returns exactly one finding, rule node-not-ready, naming the node, with metrics-server in its affected resources and no pod-crashloop finding. test_doctor_attributes_crashloop_on_an_unready_node_to_the_node asserts (rule ids, resource, affected) as one tuple.
  • The issue's second case is found: a Warning event with reason VolumeFailedDelete whose involved object is a PersistentVolume, plus a helper pod with a deletion_timestamp 3 days before k8s_fakes.NOW, yields one volume-reclaim-stuck finding naming the PV and the pod, class cluster. test_doctor_reports_a_stuck_volume_reclaim asserts it; FakeCoreV1 has no delete method, so any deletion attempt raises AttributeError.
  • Each remaining rule has one fixture test (node-cordoned, pod-stuck-terminating, pod-crashloop with OOMKilled, pod-image-pull, pod-unschedulable, pod-not-ready, warning-events, log-errors), parametrized over tests/k8s_fakes.py objects, asserting (rule, severity, class, resource, remediation is non-empty); the log-errors case asserts the evidence lines land on the pod's finding and that no finding has rule log-errors.
  • Ranking is pinned: test_doctor_ranks_cluster_findings_first builds a report with one finding of each class and severity and asserts the ordered rule ids.
  • Logs are read only for flagged pods: test_doctor_reads_logs_only_for_flagged_pods reads FakeCoreV1.calls and asserts the set of (namespace, name, tail_lines) for read_namespaced_pod_log equals the flagged pods with the --tail value.
  • Every API call carries a client-side timeout: test_doctor_calls_carry_a_timeout asserts _request_timeout == DEFAULT_K8S_CONNECT_TIMEOUT_SECONDS on every entry in FakeCoreV1.calls.
  • The command never queries Prometheus or Loki: test_doctor_uses_the_kubernetes_api_only asserts every entry in FakeCoreV1.calls is one of list_node, list_pod_for_all_namespaces, list_namespaced_pod, list_event_for_all_namespaces, list_namespaced_event or read_namespaced_pod_log, and that src/devops_cli/k8s/doctor.py imports nothing from devops_cli.commands.prometheus or devops_cli.k8s.logql.
  • --namespace narrows pods and events: test_doctor_namespace_narrows_the_calls asserts the recorded calls are list_namespaced_pod and list_namespaced_event with that namespace and list_node unchanged.
  • --format json prints DoctorReport.model_dump(): test_doctor_json_output_round_trips parses stdout and asserts (context, len(findings), findings[0]["rule"]); --format yaml parses with yaml.safe_load to the same dict.
  • Exit codes are 0 clean, 2 findings, 1 unreachable: test_doctor_exit_codes asserts (0, 2, 1) for a healthy snapshot, a snapshot with findings, and a FakeCoreV1(nodes=Exception("Token secret_token_xyz123 failed")), and asserts secret_token_xyz123 is not in the output; a second parametrization runs the snapshot with findings under --format json and --format yaml and asserts the exit code is still 2.
  • A healthy cluster prints one line saying no problems were found and exits 0; --dry-run prints a render_dry_run_result for devops k8s doctor without loading a kubeconfig and exits 0: test_doctor_dry_run_loads_no_config patches kubernetes.config.load_kube_config with side_effect=AssertionError as tests/test_k8s_logs_diff_chaos.py:124-131 patches it.
  • The k8s_doctor MCP tool exists, its docstring states that Command exited with status 2: means findings follow as JSON, and docs/MCP_TOOLS.md and docs/CLI_REFERENCE.md are regenerated: uv run devops docs check passes.
  • changelog.d/408.md is added; CHANGELOG.md and docs/ROADMAP.md are untouched, which devops pr check-readiness enforces for a PR into release/* (src/devops_cli/commands/pr.py:1649,1851-1852).
  • Every new test runs offline in under 1 s (uv run pytest tests/test_k8s_doctor.py --durations=10), and uv run devops ci passes within its 5-minute budget, including the complexity gate (DEFAULT_MAX_COMPLEXITY = 10, DEFAULT_MAX_NESTING_DEPTH = 5, config/defaults.py:677-678).
  • Pending a person: uv run devops k8s doctor --context homelab-k3s on the homelab, then uv run devops k8s doctor --context homelab-k3s --format json | head -40, and confirm the output agrees with kubectl --context homelab-k3s get nodes and kubectl --context homelab-k3s get events -A --field-selector type=Warning, and that the shell's $? is 2 when the table shows findings and 0 when it does not.

Out of Scope

  • The dashboard panel (TUI or Grafana): split off by the owner's placement comment of 2026-10-01; a follow-up candidate, not yet filed.
  • Prometheus or Loki as data sources, restart rates over time, and any --since window: decided out on 2026-10-02; a Prometheus-backed --since is a separate follow-up candidate.
  • Any remediation action: uncordon, delete, restart, finalizer removal. The local-path reclaim item owns volume cleanup.
  • Alert rules and Alertmanager routing (the Alerts fire into nothing: no Alertmanager, and k3s false positives #549 roadmap entry, docs/ROADMAP.md:1181, v0.2.28); the doctor is a pull-time report, not an alert.
  • An AI narrative over the report; k8s_diagnostics_prompt stays as it is.
  • Replacing devops k8s status, _get_unready_nodes, or the MCP k8s_pods tool, which today runs devops k8s status (server.py:275-282).
  • Migrating chaos's --json to --format; that belongs to the output-format roadmap item.
  • Changing _run_mcp_cmd's non-zero-exit prefix; the k8s_doctor tool documents it rather than special-casing status 2.

Dependencies

Sequencing: no open item depends on this one and this item depends on no open item, so it can land at any point in its release; nothing in the cross-release ordering names #408.

Readiness check (2026-10-04)

Checked at b61e5a0 (release/v0.2.26).

Dependencies. None are open:

Moved citations. The content is unchanged unless stated.

Rule alignment: dry run (#412). A dry run makes no request, reads included. It returns the real result type together with the ordered planned requests.

Rule alignment: library-first. Three triggers in the body rely on hand-written string checks:

  • the log-errors regex and line-share threshold (CONST_K8S_DOCTOR_LOG_ERROR_PATTERN, DEFAULT_K8S_DOCTOR_LOG_ERROR_RATIO);
  • joining a helper pod to a PV through event.message;
  • recognising a "local-path helper pod".

None of these is decided, and the simpler form replaces them:

  • No log line is classified. A flagged container's tail is attached as evidence on the pod's finding, passed through mask_secrets. Kubernetes' own fields name the cause: state.waiting.reason, last_state.terminated.reason, exit_code and message.
  • Both constants are dropped, and DEFAULT_K8S_DOCTOR_LOG_TAIL_LINES becomes 20, because the lines are now shown rather than counted.
  • volume-reclaim-stuck fires on the VolumeFailedDelete event on a PersistentVolume only. A stuck helper pod is reported by pod-stuck-terminating.

Amended criteria:

  • (replaces the --dry-run half of the healthy-cluster criterion) --dry-run loads no kubeconfig, makes no API call and exits 0.

    • It returns a DoctorReport with no findings. Its requests lists, in order: list_node, the pod list and the Warning event list (namespaced under --namespace), then read_namespaced_pod_log with tail_lines set to --tail, condition "a rule flags the pod" and repeat "per flagged container".
    • Table output prints the requests with render_request_plan; --format json|yaml carries them in the report.
    • test_doctor_dry_run_makes_no_request patches kubernetes.config.load_kube_config with side_effect=AssertionError. It asserts that no client is built and checks the ordered request methods.
  • (replaces the second-case criterion) A VolumeFailedDelete event on a PersistentVolume, plus a helper pod whose deletion_timestamp is 3 days before k8s_fakes.NOW, yields:

    • one volume-reclaim-stuck finding of class cluster, naming the PV;
    • one pod-stuck-terminating finding naming the pod, ranked after it.

    src/devops_cli/k8s/doctor.py never reads event.message to join objects.

  • (replaces the log-errors part of the per-rule criterion) The flagged pod's finding carries the tail lines, masked, as evidence, and no finding has rule log-errors. git grep -nE "LOG_ERROR_(PATTERN|RATIO)" -- src prints nothing.

Activity

  1. added this to the v0.2.23 milestone on Sep 22, 2026
  2. added
    type/feature
    scope/k8s
    priority/p1-high
    on Sep 22, 2026
  3. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to v0.2.26 to make room for the seven P1 items left open in the shipped v0.2.23, which were committed earlier. The roadmap-job items placed in v0.2.25 stay, and this item is among the oldest of the rest.

  4. removed this from the v0.2.26 milestone on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.26 to the backlog to make room for #843 (CI parity), by the owner's decision (2026-10-01). It heads the P1 backlog.

  6. added this to the v0.2.27 milestone on Oct 1, 2026
  7. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Placement (2026-10-01): v0.2.27. Value Medium, Effort High. Not Ready yet.

    Checked against release/v0.2.24 at d38251e. What stops it being Ready:

    • No acceptance criteria.
    • Key questions unasked:
    • Where the data comes from: the k8s API only, or Prometheus/kube-state-metrics and Loki for log error rates.
    • What the ranking and cause model is.
    • Whether 'dashboard panel' means the TUI Kubernetes tab or a Grafana dashboard.
    • Too big for one PR: a correlation engine with four signal sources, plus a dashboard panel. Split the command from the panel.
    • No file references or measured baseline. The task file still names v0.2.24.
  8. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Proposed additions from the monitoring cleanup (2026-10-03), for a person to fold in or decline. This item is owner-placed, so its scope is unchanged until then. The cleanup is grouped under #1128.

    Both checks use only the Kubernetes API.

  9. dan-petty-bot commented on Oct 6, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1252, merged into release/v0.2.27 as edd9d2f.

    Summary

    Closes #408

    Implements devops k8s doctor and its companion FastMCP tool k8s_doctor to diagnose Kubernetes cluster deployment health and correlate symptoms across nodes, workloads, and cluster events.

    Key capabilities:

    • Fixed evaluation rule table with root-cause attribution: cluster faults absorb workload symptoms (e.g. crashlooping pods on an unready or cordoned node are absorbed into the node finding).
    • Cluster-wide PersistentVolume reclaim diagnosis (VolumeFailedDelete events) and stuck terminating helper pod detection.
    • FastMCP tool k8s_doctor registered with docstring documenting status code conventions (2 indicates findings follow as JSON, 1 indicates unreachable cluster).
    • Pure function collection and diagnosis engine in src/devops_cli/k8s/doctor.py making Kubernetes API calls only (no Prometheus or LogQL dependencies).
    • Bounded container log tailing for flagged pods with secret sanitization via mask_secrets.
    • Output formatting support for table, json, and yaml with exit codes 0 (clean), 2 (findings present), and 1 (error).
    • Read-only --dry-run execution previewing ordered API requests without making requests.
    • Comprehensive offline test suite in tests/test_k8s_doctor.py covering all criteria and ranking invariants.

    18 file(s) changed.

    How it was verified

    Check runs at f378876:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-408-cluster-deployment-health-diagnosis-devops-k8s-doctor.md:

    No Acceptance Criteria section.

  10. added a commit that references this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/k8stype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions