kx diagnostic
Analyzes health signals — replica counts, container states, resource usage and warning events — and reports findings by severity.
With no index, sweeps every workload in the current namespace, or in the namespace given by -n, or in every namespace with -A; -m narrows a sweep to the resources whose name matches. Healthy resources are left out of the terminal table by default; --show-healthy includes them. The HTML report (--html) includes them either way.
A Node is diagnosed by index — from kx get nodes or kx top nodes — or by name, as node/<name>. Nodes are not namespaced, so they do not appear in a namespace sweep or in -A.
--since bounds how far back the report looks, in s, m, h or d: 90s, 30m, 12h, 7d. A fraction or a mixture works too — 1.5h, 1h30m — except with d, which takes a fraction but not a mixture: 1.5d, never 1d12h. Without it everything is reported, however old — which is what holds a resource at warnings, and a --fail-on gate red, over a failure from last month. Set diag_max_age in config.toml to choose a window once rather than per run.
A window only ever hides what finished: a warning event, a restart or OOMKill a container recovered from, a Pod or run that failed. What is still going wrong is always reported, however long it has been going wrong — a container in CrashLoopBackOff or ImagePullBackOff, a Pending Pod, a Service with no endpoints.
Every finding says which it is. ‘· for 24d’ is how long something has been true, and no window hides it; ‘· 2m ago’ is when something happened, and a narrow enough one will.
A schedule longer than the window wants a wider one: a weekly CronJob whose last run failed six days ago needs --since 7d.
A sweep is ranked most severe first, and --sort orders it on top of that, by KIND, NAME, NAMESPACE, VERDICT or TOP FINDING, with a leading - for largest first: --sort kind groups it by kind with the worst first in each, and the indexes follow the order shown. The order carries into --json and the --html page.
--limit keeps the first rows the table shows, after the ranking and any --sort: kx diag -A --limit 5 is the five worst resources, numbered 1 to 5, and the rest of the sweep is neither saved nor reported. The caption says how many it could have shown, and --fail-on still reads the whole sweep.
Usage
kx diagnostic [OPTIONS] [index]Aliases
kx diag
Arguments
| Argument | Description |
|---|---|
[index] | Row number from the current listing, @name for a mark, or kind/name such as deploy/api |
Options
| Option | Description |
|---|---|
-A, --all-namespaces | Sweep every namespace; each row is indexed and carries its own namespace |
--context string | Kubeconfig context of a kind/name target; defaults to the current one. An index carries its own |
--fail-on string | Exit 2 when a verdict reaches this severity or worse (critical, warning) |
--html | Render the report as HTML and serve it in a browser |
--json | Print the report as JSON instead of a table |
--limit int | Keep the first N rows the sweep shows, after its ranking and --sort |
-m, --match string | Match by name (substring, case-insensitive) |
-n, --namespace string | Namespace to sweep; defaults to the current namespace |
--no-open | Serve the HTML report without opening a browser |
--out string | Write the HTML report to this file instead of serving it in a browser |
--port int | Port to serve the HTML report on; 0 picks a free one |
--show-healthy | Include healthy resources in the terminal table; the HTML report includes them either way |
--since string | Ignore anything that happened longer ago than this — events, past restarts, failed runs; s, m, h or d: 90s, 30m, 12h, 7d. Defaults to diag_max_age, which is unset: everything is reported |
--sort string | Sort the sweep by its columns, on top of the severity ranking: ‘kind’ groups it by kind, the worst first in each |
Global options
| Option | Description |
|---|---|
--no-color | Disable styled output |
-h, --help | Show this message and exit |
Examples
kx diagnostic
kx diagnostic 1
kx diagnostic deploy/api -n prod
kx diagnostic deploy/api --context staging
kx diagnostic -n prod
kx diagnostic -m api
kx diagnostic --show-healthy
kx diagnostic -A --sort namespace,kind
kx diagnostic -A --limit 5
kx diagnostic -A
kx diagnostic --html
kx diagnostic -A --json
kx diagnostic --since 7d
kx diagnostic -A --fail-on critical --out report.html