feat(k8s): add k8s-diagnose for read-only workload triage
k8s-diagnose triages pods, probes, scheduling, storage and Service endpoints under a view-only kubeconfig: one evidence command per finding and a likely cause, never a fix applied. It stops with "no cluster access" or the RBAC gap instead of looking for other credentials, and accepts hand-offs from flux-diagnose. k8s 0.2.0; the .gitkeep placeholder goes now that a skill exists. Refs: #194 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
1 parent
2a6eea3db1
commit
277d6f5826
5 files changed
+172
-1
No files matched your search
@@ -0,0 +1,92 @@
|
||||
---
|
||||
name: k8s-diagnose
|
||||
description: >
|
||||
Use when a Kubernetes workload is unhealthy — pods not Ready, crash-looping or Pending — or
|
||||
`flux-diagnose` hands over a pod problem. Read-only kubectl triage. Not Flux reconcile or
|
||||
source status -> `flux-diagnose`. Not app code bugs -> `diagnose`.
|
||||
compatibility: Requires kubectl and a kubeconfig the caller supplies, exported or as a path,
|
||||
bound to the built-in view ClusterRole or a wider read-only role.
|
||||
allowed-tools: Bash Read
|
||||
metadata:
|
||||
category: k8s
|
||||
version: "0.1.0"
|
||||
source_keys:
|
||||
- adr-0032-action-tiers
|
||||
- delivery-guard-kubectl-allowlist
|
||||
---
|
||||
|
||||
## Gotchas
|
||||
|
||||
- `The connection to the server localhost:8080 was refused` means kubectl found no kubeconfig,
|
||||
not that a cluster is down. Never pick credentials yourself: no `--kubeconfig`, `--context`,
|
||||
`--as` or `--token`, no `kubectl config use-context`, no filesystem search.
|
||||
- The `view` role reads no Secrets, nodes, PersistentVolumes or StorageClasses. A Forbidden there
|
||||
is a gap to report, not a reason to retry another way.
|
||||
- `describe`, `-o yaml` and logs print inline env values and whatever the app logs. Quote only the
|
||||
lines that prove a finding and redact anything that looks like a credential.
|
||||
|
||||
## Command tiers
|
||||
|
||||
Run only the Read row. Anything else, listed or not, goes back to the caller as a
|
||||
recommendation.
|
||||
|
||||
| Tier | Commands |
|
||||
|---|---|
|
||||
| Read | `kubectl auth can-i`, `api-resources`, `explain`; `get` and `describe` on any kind but Secrets (`-o wide`, `-o jsonpath`); `logs` (`--previous`, `--tail`, `-c`, `--all-containers`); `events --for`; `top pod` when the metrics API is served |
|
||||
| Propose | None: the caller opens the fix PR |
|
||||
| Apply-by-merge | The fix itself: a manifest change in the repo, applied by Flux after an approved merge |
|
||||
| Odd job | None: `flux reconcile` is HITL-only |
|
||||
| Never | `apply`, `create`, `delete`, `edit`, `patch`, `label`, `annotate`, `scale`, `set`, `rollout restart`, `rollout undo`, `cordon`, `drain`, `taint`, `exec`, `attach`, `port-forward`, `cp`, `debug`, `proxy`, live `diff`; `get secret -o …`, `describe secret`, `get --raw` on Secrets, `config view --raw` |
|
||||
|
||||
## Step 1 — Check access
|
||||
|
||||
No namespace given → stop and report `need a namespace`, so the caller can supply one; never
|
||||
sweep `--all-namespaces`.
|
||||
|
||||
Run every command in the environment the caller gave. Given a kubeconfig path, prefix each command
|
||||
with `KUBECONFIG=<path>`: an `export` does not carry between shell calls.
|
||||
|
||||
Run `kubectl auth can-i list pods -n <ns>`:
|
||||
|
||||
- `yes` → continue.
|
||||
- `no` → stop and report `rbac gap: cannot list pods in <ns>`.
|
||||
- Any connection, certificate or `Unauthorized` error, or no kubeconfig → stop and report
|
||||
`no cluster access: <first line of the error>`.
|
||||
|
||||
A later Forbidden does not stop the run; record it under Gaps.
|
||||
|
||||
## Step 2 — Resolve the target to pods
|
||||
|
||||
- **Pod** → that pod.
|
||||
- **Workload** (Deployment, StatefulSet, DaemonSet, Job) →
|
||||
`kubectl describe <kind>/<name> -n <ns>`, then `kubectl get pods -n <ns> -l '<selector>' -o wide`
|
||||
with `<selector>` copied verbatim from the describe output's `Selector:` line, never rebuilt
|
||||
from `matchLabels`, which drops `matchExpressions`.
|
||||
- **Namespace** → `kubectl get pods -n <ns> -o wide` and
|
||||
`kubectl get deploy,sts,ds,job,pvc,svc -n <ns>`.
|
||||
|
||||
A pod is unhealthy when its phase is not `Running` or `Succeeded`, its READY count is short, or
|
||||
its restart count is climbing. Target not found → a finding; if the repo should create it, Flux
|
||||
likely never applied it: hand to `flux-diagnose`.
|
||||
|
||||
## Step 3 — Triage each unhealthy pod
|
||||
|
||||
If any pod is unhealthy, read `references/symptoms.md`: run its baseline commands on each
|
||||
unhealthy pod, then follow its symptom row.
|
||||
|
||||
## Step 4 — Check storage and Services
|
||||
|
||||
If the target's scope holds a PVC or a Service, read `references/symptoms.md` Gotchas and
|
||||
§Storage and Services: a PVC not `Bound` or a Service with no ready endpoints is a finding.
|
||||
|
||||
## Step 5 — Report
|
||||
|
||||
```text
|
||||
k8s-diagnose: <target> in <ns> — <healthy|unhealthy|need a namespace|no cluster access|rbac gap>
|
||||
- <finding> — evidence: `<command>`
|
||||
Likely cause: <one line, or "undetermined">
|
||||
Gaps: <Forbidden reads, missing metrics, or none>
|
||||
```
|
||||
|
||||
Never apply a fix; name the manifest change for the caller's PR. When the
|
||||
cause sits in the Flux layer, end with `hand to flux-diagnose: <Kustomization or HelmRelease>`.
|
||||
Reference in new issue
Block a user