Diagnose pending, crash-looping or unready Kubernetes pods with read-only kubectl get, describe, logs --previous, events and top, then propose an evidence-backed fix.
---
name: kubernetes-pod-inspector
description: Diagnoses a Kubernetes pod that is pending, crash-looping, not ready, restarting or slow, using read-only kubectl commands (get, describe, logs including --previous, events, top) against the cluster context the user already has, and returns the likely cause with the evidence and a proposed fix. Use when a pod or deployment is unhealthy, shows CrashLoopBackOff, ImagePullBackOff, OOMKilled or Pending, or someone asks to inspect a pod.
compatibility: Requires kubectl on PATH and a kubeconfig context with read access to the namespace. kubectl top needs metrics-server in the cluster.
metadata:
version: "1.0.0"
category: "Cloud Computing"
---
# Kubernetes Pod Inspector
Read-only by default. This skill never asks for credentials and never changes cluster state unless the user explicitly asks for a specific change after seeing the diagnosis.
## Inputs to collect
- Pod name or the workload (Deployment/StatefulSet/Job) and namespace.
- Which cluster: confirm the kubeconfig context to use.
- Symptom and when it started (after a deploy, config change or traffic spike).
## Preflight
1. `kubectl config current-context`. If it errors ("current-context is not set") or names an unexpected cluster, stop and ask the user which context to use (`kubectl --context <name> ...`). Do not create or edit kubeconfig entries.
2. `kubectl auth can-i get pods -n <ns>` and `kubectl auth can-i get pods/log -n <ns>` to confirm access.
## Workflow
1. **Find the pod.** `kubectl get pods -n <ns> -o wide` (or `-l app=<label>`). Note STATUS, READY, RESTARTS, AGE and NODE.
2. **Container states.**
`kubectl get pod <pod> -n <ns> -o json | jq -r '.status.containerStatuses[] | [.name, .ready, .restartCount, (.state|keys[0]), (.state[].reason // "-"), (.lastState.terminated.reason // "-"), (.lastState.terminated.exitCode // "-")] | @tsv'`
(without jq, read the same fields from `kubectl describe pod`).
3. **Describe.** `kubectl describe pod <pod> -n <ns>`: read Conditions, container Last State, limits/requests, probes, volumes and the Events at the bottom.
4. **Logs.** `kubectl logs <pod> -n <ns> -c <container> --tail=200`; for a restarting container also `--previous`, which holds the crash output.
5. **Events.** `kubectl events -n <ns> --for pod/<pod>` (or `kubectl get events -n <ns> --sort-by=.lastTimestamp`).
6. **Usage.** `kubectl top pod <pod> -n <ns> --containers` if metrics-server is installed; otherwise say usage is unavailable.
7. **Match the pattern**, citing the evidence line:
- `CrashLoopBackOff` + last state `OOMKilled`/exit 137 → memory limit too low or a leak; compare usage to limits.
- `CrashLoopBackOff` + exit 1 → application error; read `--previous` logs.
- `ImagePullBackOff`/`ErrImagePull` → wrong tag, private registry without imagePullSecret.
- `Pending` + FailedScheduling → insufficient CPU/memory, taints, node selectors, unbound PVC.
- Running but not Ready → readiness probe failing; check probe path/port and timing.
- `CreateContainerConfigError` → missing ConfigMap/Secret key.
8. **Propose the fix** as a manifest diff or command (for example raise `resources.limits.memory` in the Deployment). Apply nothing yourself unless the user asks. If they do, use `kubectl apply --dry-run=server -f <file>` first and change the owning Deployment, not the pod.
## Output format
```
POD <ns>/<pod> · context <ctx> · node <node>
State: <phase>, container <name> ready=<bool> restarts=<n> waiting=<reason> last=<reason>/<exit>
Evidence: <describe/event/log lines>
Likely cause: ... Confidence: high|medium|low (why)
Proposed fix: <diff or command> Not checked: <e.g. metrics unavailable>
```
## Limitations
- Only one `--previous` log generation is kept; earlier crashes may be lost.
- Events expire (about an hour by default), so old problems may show none.
- Do not `kubectl delete pod` to "fix" a crash loop; the controller recreates the same failing pod.
## Example
Input: "shop/api-7d9f keeps restarting."
Good result: the container row reads `api false 7 waiting CrashLoopBackOff OOMKilled 137`; describe shows `limits.memory: 256Mi`; the agent reports an OOM kill with that evidence and proposes raising the Deployment's memory limit (or profiling memory) instead of deleting the pod.
Generate a GitHub Actions (or other CI) pipeline from the repo's real scripts, with least-privilege permissions, caching, concurrency and a gated deploy.
Generate a compose.yaml for your app, database and cache with health-checked startup, named volumes and secrets in .env, validated with docker compose config.
Automate notifications and alerts
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Deployment's pod in namespace shop restarts repeatedly after a release and the on-call developer wants the cause without touching the cluster.
Pod api-7d9f in namespace shop keeps restarting since this morning's deploy. Use my current kube context and tell me why.
The agent first reports the current context and the `kubectl auth can-i` results. The container-state line (from the jq filter in the skill) reads something like `api false 7 waiting CrashLoopBackOff OOMKilled 137`. Supporting evidence comes from `kubectl describe` (limits.memory 256Mi, Back-off events), `kubectl logs --previous`, and `kubectl top` if metrics-server exists; otherwise it says usage is unavailable. Conclusion: the container is OOM-killed at its memory limit. The proposed fix is a Deployment diff raising resources.limits.memory, or memory profiling, with no pod deletion and nothing applied.
AI Agent Skills are reusable workflow packages that extend your AI coding assistant with multi-step capabilities. Install Kubernetes Pod Inspector by following these steps.
SKILL.md inside, in the location documented by your client. Do not assume every AI application reads the same directory.Requires an Agent Skills-compatible client; supported locations and activation vary by version. Read the SKILL.md setup guide. MCP connects tools and data and does not, by itself, install a skill.
Generate a GitHub Actions (or other CI) pipeline from the repo's real scripts, with least-privilege permissions, caching, concurrency and a gated deploy.
Generate a compose.yaml for your app, database and cache with health-checked startup, named volumes and secrets in .env, validated with docker compose config.
Automate notifications and alerts