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
4.3 KiB
name, description, compatibility, allowed-tools, metadata
| name | description | compatibility | allowed-tools | metadata | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| k8s-diagnose | 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`. | 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. | Bash Read |
|
Gotchas
The connection to the server localhost:8080 was refusedmeans kubectl found no kubeconfig, not that a cluster is down. Never pick credentials yourself: no--kubeconfig,--context,--asor--token, nokubectl config use-context, no filesystem search.- The
viewrole reads no Secrets, nodes, PersistentVolumes or StorageClasses. A Forbidden there is a gap to report, not a reason to retry another way. describe,-o yamland 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 reportrbac gap: cannot list pods in <ns>.- Any connection, certificate or
Unauthorizederror, or no kubeconfig → stop and reportno 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>, thenkubectl get pods -n <ns> -l '<selector>' -o widewith<selector>copied verbatim from the describe output'sSelector:line, never rebuilt frommatchLabels, which dropsmatchExpressions. - Namespace →
kubectl get pods -n <ns> -o wideandkubectl 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
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>.