diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
new file mode 100644
index 0000000..1a4192f
--- /dev/null
+++ b/.github/workflows/docs.yml
@@ -0,0 +1,70 @@
+name: Docs
+
+# Builds the MkDocs site on every relevant PR (strict mode, so broken links and
+# warnings fail) and deploys it to GitHub Pages when changes land on main.
+# Site: https://ngpayyappilly.github.io/k8s-debug/
+
+on:
+ push:
+ branches: [main]
+ paths:
+ - docs/**
+ - mkdocs.yml
+ - scripts/check-docs.sh
+ - scripts/smoke-test.sh
+ - .github/workflows/docs.yml
+ pull_request:
+ paths:
+ - docs/**
+ - mkdocs.yml
+ - scripts/check-docs.sh
+ - scripts/smoke-test.sh
+ - .github/workflows/docs.yml
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: pages
+ cancel-in-progress: false
+
+jobs:
+ build:
+ runs-on: ubuntu-24.04
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Every shipped tool is documented
+ run: scripts/check-docs.sh
+
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+ cache: pip
+ cache-dependency-path: docs/requirements.txt
+
+ - run: pip install -r docs/requirements.txt
+
+ - name: Build site
+ run: mkdocs build --strict
+
+ - name: Upload Pages artifact
+ if: github.event_name != 'pull_request'
+ uses: actions/upload-pages-artifact@v3
+ with:
+ path: site
+
+ deploy:
+ if: github.event_name != 'pull_request'
+ needs: build
+ runs-on: ubuntu-24.04
+ permissions:
+ pages: write
+ id-token: write
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ steps:
+ - id: deployment
+ uses: actions/deploy-pages@v4
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..45ddf0a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+site/
diff --git a/README.md b/README.md
index f3f9aab..74a975a 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,8 @@
Ubuntu 24.04 image for `kubectl debug` ephemeral containers. Multi-arch (amd64 + arm64).
+**Documentation: **: every tool, install steps, permissions, and troubleshooting recipes.
+
**Tools:** curl, wget, dig/nslookup/drill, ping, traceroute, mtr, tcpdump, nmap, ncat/nc, socat, ss/ip, iptables/nft, conntrack, ethtool, iperf3, openssl, strace, ltrace, gdb, lsof, htop, sysstat (pidstat/iostat), iotop, bpftrace, jq, yq, kubectl, stern, grpcurl, git, ssh, python3, vi/nano.
## Build and push
@@ -47,11 +49,11 @@ kubectl debug -it -n --image=/k8s-debug:1.0.0 \
| Need | Profile | Grants |
|---|---|---|
-| `ps`, `/proc//root`, `strace` | `general` | `SYS_PTRACE` |
-| `tcpdump`, `iptables`, raw sockets | `netadmin` | `NET_ADMIN`, `NET_RAW` |
+| shell, `tcpdump`, `ping`, `ps`, `/proc//root`, `strace`, `gdb` | `general` (default) | runtime defaults (incl. `NET_RAW`) + `SYS_PTRACE` |
+| `iptables`, `conntrack`, `ip link`/`route` changes | `netadmin` | runtime defaults + `NET_ADMIN` (no `SYS_PTRACE`) |
| everything / node-level | `sysadmin` | privileged |
-Some tools need both ptrace and network caps. Profiles can't be combined, so use `netadmin` plus a custom patch, or `sysadmin` for a short session:
+Profiles can't be combined, and `--custom` capability lists *replace* the profile's, so list every capability you want:
```sh
kubectl debug -it --image=... --target= \
diff --git a/docs/contributing.md b/docs/contributing.md
new file mode 100644
index 0000000..bbc224b
--- /dev/null
+++ b/docs/contributing.md
@@ -0,0 +1,71 @@
+# Contributing
+
+The source is at [github.com/ngpayyappilly/k8s-debug](https://github.com/ngpayyappilly/k8s-debug). Changes go
+through pull requests to `main`.
+
+## Add or change a tool
+
+1. Add the package to the `apt-get install` list in the `Dockerfile` (or, for a standalone binary, add a pinned,
+ **checksum-verified** download step like the existing ones).
+2. Add the command name to the `TOOLS` list in `scripts/smoke-test.sh`.
+3. Document it: add a `## \`toolname\`` section to the matching page under `docs/tools/`, with the package, the
+ permissions it needs, and examples for Kubernetes situations.
+4. Add it to the tables in `docs/index.md`, `docs/tools/index.md` and the banner in `motd.txt` if it is
+ important enough to advertise.
+5. Run the checks (below) and open a PR.
+
+The documentation check fails the build if a tool in the smoke test has no section, so docs cannot silently fall
+behind the image.
+
+## Run the checks locally
+
+```sh
+docker build -t k8s-debug:dev .
+scripts/smoke-test.sh k8s-debug:dev # every tool exists and binaries run
+scripts/check-docs.sh # every tool is documented
+
+pip install -r docs/requirements.txt
+mkdocs serve # live preview at http://127.0.0.1:8000
+mkdocs build --strict # what CI runs; broken links fail
+```
+
+Pull requests also run `hadolint`, `shellcheck` and `actionlint`, and build and smoke-test the image on both
+amd64 and arm64.
+
+## Writing documentation
+
+- Say **what the tool is for** in Kubernetes terms before listing flags.
+- Every example should be something you have run. State the permission it needs.
+- Prefer tested facts over general knowledge. If behaviour depends on the cluster, runtime or kubectl version,
+ say so.
+- Use `ghcr.io/ngpayyappilly/k8s-debug:latest` in examples, and placeholders such as `` for things the
+ reader must replace.
+
+## Releases
+
+Releases are cut by pushing a version tag:
+
+```sh
+git tag v1.2.3 && git push origin v1.2.3
+```
+
+The publish workflow builds both platforms and pushes `1.2.3`, `1.2`, `1` and `latest`. Pre-release tags such as
+`v1.3.0-rc.1` publish only that exact tag. Pushes to `main` publish `edge` and `sha-`.
+The documentation site is rebuilt and deployed from `main` whenever `docs/` or `mkdocs.yml` changes.
+
+## Extend the image for your own needs
+
+If your platform needs tools that are not here (a JDK, `py-spy`, a database client), build on top:
+
+```dockerfile
+FROM ghcr.io/ngpayyappilly/k8s-debug:1.2.3
+
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends redis-tools postgresql-client \
+ && rm -rf /var/lib/apt/lists/*
+
+COPY team-aliases.sh /etc/team-aliases.sh
+RUN echo '. /etc/team-aliases.sh' >> /root/.bashrc
+```
+
+Pin the base to an exact version so your image changes only when you choose.
diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md
new file mode 100644
index 0000000..742f75f
--- /dev/null
+++ b/docs/getting-started/installation.md
@@ -0,0 +1,196 @@
+# Installation
+
+There is nothing to install. The image is public and Kubernetes pulls it when you run `kubectl debug`.
+This page covers what you need, every way to start a session, and how to pin, mirror or build the image.
+
+## Requirements
+
+| What | Version | Why |
+|---|---|---|
+| Kubernetes | 1.25+ | Ephemeral containers are GA from 1.25 |
+| `kubectl` | 1.31+ recommended | Older versions lack `--custom` and some `--profile` values |
+| Container runtime | containerd or CRI-O | `--target` (shared process namespace) needs runtime support |
+| Node OS | Linux | The image is Linux only |
+| RBAC | see [Permissions](permissions.md#rbac-what-you-need-to-be-allowed-to-do) | You need to be allowed to add ephemeral containers |
+
+Check your client and server:
+
+```sh
+kubectl version
+```
+
+## Image and tags
+
+```text
+ghcr.io/ngpayyappilly/k8s-debug
+```
+
+| Tag | Meaning |
+|---|---|
+| `1.2.3` | An exact release. **Use this in runbooks and automation.** |
+| `1.2` | Latest patch of a minor version |
+| `1` | Latest minor of a major version (not published for `0.x`) |
+| `latest` | The newest stable release (pre-releases are excluded) |
+| `edge` | The tip of `main`. Unreleased, may change at any time |
+| `sha-abc1234` | A specific commit on `main` |
+
+Releases are listed on the [GitHub releases and tags page](https://github.com/ngpayyappilly/k8s-debug/tags).
+
+!!! note "No `latest` yet?"
+ `latest` appears with the first stable version tag. Until then use `edge`.
+
+## Ways to use it
+
+### 1. Attach to a running pod (the usual way)
+
+```sh
+kubectl debug -it -n \
+ --image=ghcr.io/ngpayyappilly/k8s-debug:latest \
+ --target=
+```
+
+- Adds an ephemeral container to the **existing** pod. Nothing restarts.
+- Shares the pod's network namespace always, and the target container's **process** namespace because of
+ `--target`.
+- Without `--target` you only share the network.
+- Name it with `--container=my-debug` so you can find it later (`kubectl logs -c my-debug`).
+
+By default `kubectl` uses the `general` profile, which includes `SYS_PTRACE` (so `strace` and `gdb` work).
+See [Permissions and profiles](permissions.md) for the others.
+
+### 2. Debug a pod that keeps crashing
+
+An ephemeral container needs a running pod. If the app crashes immediately, debug a **copy** instead:
+
+```sh
+kubectl debug -it --copy-to=-debug \
+ --image=ghcr.io/ngpayyappilly/k8s-debug:latest \
+ --share-processes
+```
+
+Variations:
+
+```sh
+# Replace the crashing container's command so it stays up, then inspect it
+kubectl debug -it --copy-to=-debug --container= -- sleep 1d
+
+# Swap the app image for the debug image in the copy
+kubectl debug -it --copy-to=-debug --set-image==ghcr.io/ngpayyappilly/k8s-debug:latest
+
+# Remove the original pod once the copy exists
+kubectl debug -it --copy-to=-debug --replace --image=...
+```
+
+Delete the copy when you are done: `kubectl delete pod -debug`.
+
+### 3. Debug a node
+
+```sh
+kubectl debug node/ -it \
+ --image=ghcr.io/ngpayyappilly/k8s-debug:latest \
+ --profile=sysadmin
+```
+
+This creates a pod on that node. The node's root filesystem is mounted at `/host`, and the pod uses the
+node's network and process namespaces. Use it for kubelet, CNI, `kube-proxy` and kernel problems:
+
+```sh
+ls /host/var/log/pods
+nsenter -t 1 -m -u -i -n -p -- systemctl status kubelet
+iptables -t nat -S KUBE-SERVICES | head
+```
+
+Delete the pod afterwards: `kubectl delete pod node-debugger--`.
+
+### 4. A standalone debug pod
+
+For network tests between pods (for example `iperf3`), or to test from a namespace without touching an
+existing workload:
+
+```sh
+kubectl run debug --rm -it --image=ghcr.io/ngpayyappilly/k8s-debug:latest -n -- bash
+```
+
+### 5. Locally with Docker
+
+The same toolbox on your laptop, handy for trying commands or inspecting files:
+
+```sh
+docker run --rm -it ghcr.io/ngpayyappilly/k8s-debug:latest
+
+# Share the host network (Linux) or mount a kubeconfig
+docker run --rm -it --network host ghcr.io/ngpayyappilly/k8s-debug:latest
+docker run --rm -it -v ~/.kube:/root/.kube:ro ghcr.io/ngpayyappilly/k8s-debug:latest
+```
+
+### Make it a shell function
+
+```sh
+# ~/.bashrc or ~/.zshrc
+kdebug() { # kdebug [namespace]
+ kubectl debug -it "$1" -n "${3:-default}" --target="$2" \
+ --image=ghcr.io/ngpayyappilly/k8s-debug:latest
+}
+```
+
+## Private clusters and air-gapped registries
+
+Nodes must be able to pull the image. If they cannot reach `ghcr.io`, mirror it to a registry they can reach:
+
+```sh
+# Copies every platform, preserving the multi-arch manifest
+crane copy ghcr.io/ngpayyappilly/k8s-debug:1.2.3 registry.example.com/tools/k8s-debug:1.2.3
+# or
+docker buildx imagetools create -t registry.example.com/tools/k8s-debug:1.2.3 \
+ ghcr.io/ngpayyappilly/k8s-debug:1.2.3
+```
+
+Then use `--image=registry.example.com/tools/k8s-debug:1.2.3`. Ephemeral containers cannot set
+`imagePullSecrets`. They use the pod's existing pull secrets, so a private mirror must be pullable with the
+secrets the pod already has (or be public inside the cluster).
+
+## Build it yourself
+
+```sh
+git clone https://github.com/ngpayyappilly/k8s-debug && cd k8s-debug
+docker build -t k8s-debug:dev .
+
+# Optional extras
+docker build --build-arg INSTALL_DB_CLIENTS=true -t k8s-debug:db . # redis-cli, psql, mysql
+docker build --build-arg KUBECTL_VERSION=v1.34.2 -t k8s-debug:k134 . # match your cluster
+
+scripts/smoke-test.sh k8s-debug:dev
+```
+
+| Build argument | Default | Meaning |
+|---|---|---|
+| `KUBECTL_VERSION` | `v1.36.1` | `kubectl` release to install. Stay within one minor of your cluster |
+| `YQ_VERSION` | `v4.47.1` | `yq` release |
+| `GRPCURL_VERSION` | `1.9.3` | `grpcurl` release (no `v` prefix) |
+| `STERN_VERSION` | `1.33.0` | `stern` release (no `v` prefix) |
+| `INSTALL_DB_CLIENTS` | `false` | Add `redis-cli`, `psql` and `mysql` (about 60 MB) |
+
+`kubectl`, `yq`, `grpcurl` and `stern` are downloaded from their upstream releases and **checksum verified**
+during the build. Everything else comes from Ubuntu's apt repositories.
+
+## Verify what you pulled
+
+```sh
+# Platforms and digest
+docker buildx imagetools inspect ghcr.io/ngpayyappilly/k8s-debug:1.2.3
+
+# Provenance and SBOM attestations published with each release build
+docker buildx imagetools inspect ghcr.io/ngpayyappilly/k8s-debug:1.2.3 --format '{{ json .Provenance }}'
+docker buildx imagetools inspect ghcr.io/ngpayyappilly/k8s-debug:1.2.3 --format '{{ json .SBOM }}'
+
+# Exact versions of the apt-installed tools in a given tag
+docker run --rm --entrypoint dpkg ghcr.io/ngpayyappilly/k8s-debug:1.2.3 -l
+```
+
+For anything security sensitive, pin by digest (`image@sha256:...`) rather than by tag.
+
+## Next
+
+- [Permissions and profiles](permissions.md): what the container is allowed to do, and how to grant more.
+- [Tools](../tools/index.md): documentation for every utility.
+- [Troubleshooting](../troubleshooting.md): when `kubectl debug` does not behave.
diff --git a/docs/getting-started/permissions.md b/docs/getting-started/permissions.md
new file mode 100644
index 0000000..6408e00
--- /dev/null
+++ b/docs/getting-started/permissions.md
@@ -0,0 +1,120 @@
+# Permissions and profiles
+
+What a debug container can do depends on three things: the **RBAC** you have, the **profile** you start it
+with, and the **security context of the pod** you attach to. Most "it doesn't work" reports come from one of
+these.
+
+## RBAC: what you need to be allowed to do
+
+| Action | Verb on resource |
+|---|---|
+| Add an ephemeral container | `patch` (or `update`) on `pods/ephemeralcontainers`, plus `get` on `pods` |
+| Open a shell (`-it`) | `create` on `pods/attach` |
+| `kubectl exec` into the debug container | `create` on `pods/exec` |
+| Read its output with `kubectl logs` | `get` on `pods/log` |
+| Debug a node, or `--copy-to` a pod | `create` on `pods` |
+
+Check yours with:
+
+```sh
+kubectl auth can-i patch pods/ephemeralcontainers -n
+kubectl auth can-i create pods/attach -n
+```
+
+## Profiles
+
+`kubectl debug --profile=` picks the security settings of the container it creates. The values below
+were observed with kubectl 1.36 against a containerd node.
+
+| Profile | Capabilities (effective) | Use it for |
+|---|---|---|
+| `general` (default) | the runtime defaults **plus `SYS_PTRACE`** | Most debugging: shell, network tools, `strace`, `gdb`, reading the target's files |
+| `netadmin` | the runtime defaults **plus `NET_ADMIN`**, and **without** `SYS_PTRACE` | Changing network config: `iptables`, `conntrack`, `ip link`/`ip route` writes, promiscuous capture |
+| `sysadmin` | **all** capabilities, privileged | `bpftrace`, `dmesg`, kernel and node level work |
+| `baseline` | for namespaces enforcing the Baseline Pod Security Standard | Clusters that reject the others |
+| `restricted` | for namespaces enforcing the Restricted Pod Security Standard | Strict clusters. Needs a non-root user, see below |
+
+The runtime defaults already include `NET_RAW`, `CHOWN`, `KILL`, `SETUID`, `SETGID`, `NET_BIND_SERVICE` and a few others.
+That is why **`tcpdump`, `ping` and `traceroute` work with the default profile**.
+
+!!! note "`netadmin` removes `SYS_PTRACE`"
+ Profiles are alternatives, not layers. Under `netadmin` you can reconfigure the network but `strace` and
+ `gdb` against other processes may fail. To get both, use `--custom` (below).
+
+### On a node
+
+`kubectl debug node/` always mounts the node's filesystem at `/host` and shares the node's network and
+process namespaces. `general` gives the default capabilities; `sysadmin` additionally makes the pod
+privileged. Use `sysadmin` for `nsenter`, `dmesg`, `bpftrace` and anything that touches the kernel.
+
+## Adding or changing capabilities with `--custom`
+
+`--custom` takes a JSON file that is merged over the container `kubectl` generates:
+
+```sh
+cat > caps.json <<'EOF'
+{"securityContext": {"capabilities": {"add": ["SYS_PTRACE", "NET_ADMIN"]}}}
+EOF
+
+kubectl debug -it --image=ghcr.io/ngpayyappilly/k8s-debug:latest \
+ --target= --profile=general --custom=caps.json
+```
+
+!!! warning "`--custom` replaces lists, it does not append to them"
+ The `add` list in your file **replaces** the profile's list. The profile `general` adds `SYS_PTRACE`;
+ if your file adds only `NET_ADMIN`, you get `NET_ADMIN` and **lose** `SYS_PTRACE`. List every capability
+ you want.
+
+## Pods that run as non-root
+
+An ephemeral container inherits the pod-level `securityContext`. If the pod sets
+`runAsUser: 1000` and `runAsNonRoot: true`, your debug container runs as UID 1000 with **no
+capabilities at all**. In that situation:
+
+- `tcpdump` fails with *You don't have permission to perform this capture*
+- you cannot read `/proc//root` of the target (*Permission denied*)
+
+Override the user with `--custom`:
+
+```sh
+echo '{"securityContext": {"runAsUser": 0, "runAsNonRoot": false}}' > root.json
+
+kubectl debug -it --image=ghcr.io/ngpayyappilly/k8s-debug:latest \
+ --target= --custom=root.json
+```
+
+If the namespace enforces the Restricted Pod Security Standard, root is not allowed. The image itself has no
+non-root user set, so `--profile=restricted` on its own fails with `CreateContainerConfigError`
+(*container has runAsNonRoot and image will run as root*). Give it a numeric user:
+
+```sh
+echo '{"securityContext": {"runAsUser": 1000}}' > uid.json
+kubectl debug -it --image=... --target= --profile=restricted --custom=uid.json
+```
+
+You will then have no capabilities, which is still enough for `curl`, `dig`, `nslookup`, `ss`, `openssl`,
+`jq`, `kubectl` and reading anything the pod's own user can read, but not for packet capture or `strace`.
+
+## Which tools need what
+
+| Needs | Tools |
+|---|---|
+| Nothing special | `curl` `wget` `nc` `ncat` `socat` `openssl` `iperf3` `dig` `nslookup` `drill` `ip` (read) `ss` `ps` `top` `free` `lsof` `jq` `yq` `kubectl` `stern` `grpcurl` `git` `python3` |
+| `NET_RAW` (in the runtime defaults) | `ping`, `traceroute` (ICMP and TCP modes), `mtr`, `tcpdump`, `arping`, `nmap` raw scans |
+| `SYS_PTRACE` (in `general`) | `strace` `ltrace` `gdb` attaching to another process; reading `/proc//root`, `/proc//environ` of processes running as a different user |
+| `NET_ADMIN` (in `netadmin`) | `iptables`/`nft`/`ipset` changes, `conntrack`, `ip link`/`ip route` changes, `ethtool` writes, `tcpdump` promiscuous mode (use `-p` to avoid it) |
+| `SYS_ADMIN` and more (in `sysadmin`) | `bpftrace`, `dmesg`, `nsenter` into other namespaces, mounting, `iotop` |
+| `--target` (shared processes) | seeing the app's processes in `ps`, `lsof`, `strace -p`, `/proc//root` |
+
+## Security notes
+
+- **Sessions are recorded.** `kubectl debug -it` prints
+ *All commands and output from this session will be recorded in container logs, including credentials and
+ sensitive information passed through the command prompt.* Do not paste secrets into the shell.
+- **No removal.** An ephemeral container cannot be deleted or edited. It stays in the pod spec (as
+ `Terminated`) until the pod is replaced. Name your containers and expect that history to remain.
+- **Service account token.** Ephemeral containers do **not** get the pod's service account token mounted. See
+ [kubectl](../tools/kubernetes.md#kubectl) for how to borrow the target's.
+- **Audit.** Adding an ephemeral container is an API write (`pods/ephemeralcontainers`) and appears in the
+ Kubernetes audit log.
+- **Least privilege.** Start with the default profile. Reach for `sysadmin` only when you need the kernel.
diff --git a/docs/index.md b/docs/index.md
new file mode 100644
index 0000000..949f848
--- /dev/null
+++ b/docs/index.md
@@ -0,0 +1,67 @@
+# k8s-debug
+
+A container image packed with debugging tools, built to be attached to a **running pod** (or node) with
+`kubectl debug`, so you can investigate live without rebuilding or restarting anything.
+
+Production images should stay small and locked down: no shell, no `curl`, no `tcpdump`. When something goes
+wrong you still need those tools. `kubectl debug` adds a temporary
+[ephemeral container](https://kubernetes.io/docs/concepts/workloads/pods/ephemeral-containers/) to the pod
+that shares its network (and, optionally, its processes), and this image is what you run in it.
+
+## 30-second start
+
+```sh
+kubectl debug -it -n \
+ --image=ghcr.io/ngpayyappilly/k8s-debug:latest \
+ --target=
+```
+
+You land in a shell inside the pod's network namespace, with the target container's processes visible:
+
+```text
+ k8s-debug ephemeral container
+ ------------------------------------------------------------------
+ Network dig nslookup curl nc socat tcpdump nmap mtr traceroute ss ip ...
+ Process ps top htop strace ltrace gdb lsof bpftrace pidstat iostat ...
+ K8s kubectl (k) stern grpcurl yq jq
+ ...
+[debug] my-pod:~ #
+```
+
+!!! tip "Is this your first time?"
+ Read [Installation](getting-started/installation.md) for every way to run it (attach to a pod, copy a
+ crashing pod, debug a node, run locally with Docker), then
+ [Permissions and profiles](getting-started/permissions.md) to understand what the container is allowed to do.
+
+## What is in the box
+
+| Area | Tools | Page |
+|---|---|---|
+| HTTP and connectivity | `curl` `wget` `nc` `ncat` `socat` `openssl` `iperf3` `ping` `tracepath` `traceroute` `mtr` `nmap` | [Connectivity](tools/connectivity.md) |
+| DNS | `dig` `nslookup` `drill` | [DNS](tools/dns.md) |
+| Network stack | `ip` `ss` `arping` `ethtool` `ifconfig` `netstat` `brctl` | [Network stack](tools/network-stack.md) |
+| Packet capture and firewall | `tcpdump` `iptables` `nft` `ipset` `conntrack` | [Packets and firewall](tools/packets-firewall.md) |
+| Processes and system | `ps` `top` `htop` `lsof` `strace` `ltrace` `gdb` `bpftrace` `pidstat` `iostat` `nsenter` ... | [Processes](tools/processes.md) |
+| Kubernetes and data | `kubectl` `stern` `grpcurl` `yq` `jq` | [Kubernetes](tools/kubernetes.md) |
+| Shell and files | `bash` `vi` `nano` `less` `git` `ssh` `python3` ... | [Shell](tools/shell.md) |
+
+Every tool has its own section with what it is for, copy-pasteable examples for Kubernetes situations, and
+the permissions it needs.
+
+## Looking for a task, not a tool?
+
+The [Recipes](recipes.md) page is organised by symptom: *connection refused*, *DNS is slow*, *the pod is
+being throttled*, *capture traffic and open it in Wireshark*, *read the app's config from its own filesystem*.
+
+## Image facts
+
+- **Registry:** `ghcr.io/ngpayyappilly/k8s-debug` (public, no login required)
+- **Platforms:** `linux/amd64`, `linux/arm64`
+- **Base:** Ubuntu 24.04 (glibc, so `gdb`, `strace` and `bpftrace` behave)
+- **Size:** about 740 MB. Pre-pull it on nodes if you debug under time pressure.
+- **Runs as:** root by default. See [Permissions](getting-started/permissions.md#pods-that-run-as-non-root).
+- **Source:** [github.com/ngpayyappilly/k8s-debug](https://github.com/ngpayyappilly/k8s-debug)
+
+!!! warning "Be deliberate with production"
+ Ephemeral containers cannot be removed from a pod once added, and an interactive session is recorded in
+ the container logs, including anything you type. Treat a debug session like a change to production.
diff --git a/docs/recipes.md b/docs/recipes.md
new file mode 100644
index 0000000..6b107a7
--- /dev/null
+++ b/docs/recipes.md
@@ -0,0 +1,228 @@
+# Recipes
+
+Start from the symptom. Each recipe assumes you attached with
+`kubectl debug -it --image=ghcr.io/ngpayyappilly/k8s-debug:latest --target=`.
+
+## Connection refused or timing out
+
+Work from the outside in. The failure mode tells you where to look.
+
+```sh
+# 1. What does the client actually see? (timing shows which phase is slow or failing)
+curl -sv -m 5 -o /dev/null http://my-svc.my-ns.svc.cluster.local:8080/
+
+# 2. Does the name resolve, and to what?
+dig +short my-svc.my-ns.svc.cluster.local
+
+# 3. Is the port reachable on the Service IP and on a backend pod IP directly?
+nc -zv -w 3 8080
+kubectl get endpointslices -l kubernetes.io/service-name=my-svc -o wide
+nc -zv -w 3 8080
+```
+
+| What you see | It usually means |
+|---|---|
+| `Connection refused` (immediate) | The IP is reachable but **nothing is listening** on that port. Check the app's port and `targetPort` |
+| `timed out` | Packets are being **dropped**: NetworkPolicy, security group, wrong IP, or no route |
+| Works on the pod IP, fails on the Service IP | `kube-proxy` or CNI Service handling. Check the Service has endpoints and the selector matches |
+| Fails only from some pods | NetworkPolicy or node-specific problem. Repeat from a pod on another node |
+| Name does not resolve | See [DNS](#dns-is-slow-or-failing) |
+
+To prove packets leave the pod and whether anything answers:
+
+```sh
+tcpdump -i any -nn -p 'host and tcp port 8080'
+```
+
+A SYN with no reply is a drop. An immediate `[R.]` is a refusal. See [`tcpdump`](tools/packets-firewall.md#tcpdump).
+Then check on the **server** side whether the SYN arrived at all.
+
+## DNS is slow or failing
+
+```sh
+cat /etc/resolv.conf # note nameserver and ndots
+dig my-svc.my-ns.svc.cluster.local # status and "Query time"
+dig @10.96.0.10 example.com # ask the cluster DNS directly
+dig @8.8.8.8 example.com # compare with an upstream: is CoreDNS the problem?
+tcpdump -i any -nn -p port 53 # watch queries and answers (and timeouts)
+```
+
+Common causes:
+
+- **`ndots:5` amplification.** Looking up `api.example.com` first tries
+ `api.example.com.my-ns.svc.cluster.local`, `...svc.cluster.local`, `...cluster.local` and only then the real
+ name. Append a trailing dot (`api.example.com.`) to prove it, then fix with `dnsConfig: options: ndots: 2` on
+ the pod, or fully qualify names in the app.
+- **Intermittent 5-second delays** on lookups: classic conntrack race with parallel A and AAAA queries. Look for
+ `insert_failed` in [`conntrack -S`](tools/packets-firewall.md#conntrack) on the node, or use a node-local DNS
+ cache.
+- **`SERVFAIL`**: the cluster DNS could not reach its upstream. Compare `dig @` with `dig @8.8.8.8`.
+- **Large answers failing**: `dig +tcp` works but UDP does not, so check MTU and a firewall dropping fragments.
+
+## TLS certificate problems
+
+```sh
+# What does the server present, and is it valid?
+openssl s_client -connect my-svc.my-ns.svc:443 -servername my-svc.example.com &1 | grep -E 'subject|issuer|Verify|notAfter'
+
+# Subject alternative names, dates, issuer
+openssl s_client -connect my-svc:443 -servername my-svc.example.com /dev/null \
+ | openssl x509 -noout -ext subjectAltName -dates -issuer
+
+# What the client would say (error text is in curl's output)
+curl -v https://my-svc.example.com/ 2>&1 | grep -iE 'ssl|tls|certificate|verify'
+```
+
+- `unable to get local issuer certificate`: the CA is not trusted here. Pass `--cacert` or install it (see
+ [`python3`](tools/shell.md#python3) note on `update-ca-certificates`).
+- `certificate has expired`: check `notAfter`. For a Secret-based certificate decode it as shown in
+ [`openssl`](tools/connectivity.md#openssl).
+- `hostname mismatch`: connect with the name in the certificate's SANs, or fix the SANs.
+- Handshake works on a pod IP but not through a mesh or ingress: use `-servername` to send the right SNI.
+
+## The pod is slow or being throttled
+
+CPU throttling is invisible in `top`. Read the target's **cgroup**:
+
+```sh
+P=1 # the app's PID in the shared namespace
+cat /proc/$P/root/sys/fs/cgroup/cpu.max # " ", or "max 100000" for no limit
+cat /proc/$P/root/sys/fs/cgroup/cpu.stat # nr_throttled and throttled_usec: rising means throttling
+cat /proc/$P/root/sys/fs/cgroup/memory.max
+cat /proc/$P/root/sys/fs/cgroup/memory.current
+cat /proc/$P/root/sys/fs/cgroup/memory.events # oom_kill > 0 means it was OOM-killed
+```
+
+Then see where the time goes:
+
+```sh
+pidstat -u -w -p $P 1 5 # CPU and context switches
+pidstat -d -p $P 1 5 # disk I/O
+ss -ti dst # TCP retransmits and RTT to a dependency
+strace -c -f -p $P # which system calls dominate (Ctrl-C after ~10 s)
+```
+
+!!! note
+ These paths use cgroup v2, standard on current distributions. On cgroup v1 nodes the files are under
+ `/sys/fs/cgroup/cpu/` and `/sys/fs/cgroup/memory/` (for example `cpu.cfs_quota_us`, `memory.limit_in_bytes`).
+
+## The app hangs and nothing is logged
+
+```sh
+# Where is every thread right now?
+gdb -p 1 -batch -ex 'thread apply all bt' -ex detach 2>&1 | less
+
+# What is it waiting on? (stop after a few seconds with Ctrl-C)
+strace -f -tt -T -p 1 2>&1 | head -50
+
+# Is it stuck on a socket?
+ss -tnp | grep -v LISTEN
+lsof -p 1 | grep -E 'TCP|IPv4' | head
+```
+
+Many threads in `futex` mean lock contention or a deadlock. A thread in `read` or `recvfrom` on one connection
+points at a dependency that never answers. A state of `D` in `ps` means it is stuck in the kernel on I/O.
+
+## File descriptor or port problems
+
+```sh
+ls /proc/1/fd | wc -l # open descriptors now
+grep 'open files' /proc/1/limits # the limit
+lsof -p 1 | awk '{print $5}' | sort | uniq -c | sort -rn # by type: sock, REG, pipe...
+ss -tn | awk '{print $1}' | sort | uniq -c # sockets per state
+fuser -v 8080/tcp # who owns the port
+```
+
+A `Too many open files` error with a count near the limit is a leak or a limit that is too low. Many
+`CLOSE-WAIT` sockets mean the app is not closing connections.
+
+## Read the app's files, config and environment
+
+You do not need a shell in the app's image:
+
+```sh
+ls $(troot 1)/ # same as ls /proc/1/root/
+cat $(troot 1)/etc/app/config.yaml
+tr '\0' '\n' < /proc/1/environ | sort # its environment variables
+cat /proc/1/cmdline | tr '\0' ' '; echo # exact command line
+ls -l /proc/1/cwd # current working directory
+```
+
+This also works on **distroless** and scratch images that have no shell. Mounted volumes, Secrets and ConfigMaps
+appear at the same paths the app sees. `$(troot 1)` is the helper that prints `/proc/1/root`.
+
+## Capture traffic and open it in Wireshark
+
+Capturing inside the pod and saving to the debug container's disk is easy. Getting the file out is the part
+that needs care. Create the container so it stays up, then stream the capture with `kubectl exec`:
+
+```sh
+# 1. A long-lived debug container named "capture"
+kubectl debug -n --container=capture \
+ --image=ghcr.io/ngpayyappilly/k8s-debug:latest --target= -- sleep 3600
+
+# 2. Stream packets straight to a local file (Ctrl-C to stop, or add -c )
+kubectl exec -n -c capture -- tcpdump -i any -U -nn -p -s0 -w - 'tcp port 8080' > capture.pcap
+
+# 3. Open capture.pcap in Wireshark
+```
+
+Or write the file in the pod and copy it out:
+
+```sh
+kubectl exec -c capture -- tcpdump -i any -nn -p -s0 -c 500 -w /tmp/capture.pcap 'tcp port 8080'
+kubectl cp :/tmp/capture.pcap ./capture.pcap -c capture
+```
+
+!!! warning "Use `exec`, not `kubectl debug -i`, for binary output"
+ Streaming a capture through `kubectl debug -i ... -w -` can lose the data because the output is not
+ attached to your terminal. Creating the container first and using `kubectl exec` is reliable.
+
+Remember the capture contains whatever the traffic contains. TLS traffic is encrypted, but headers, SNI and
+plaintext protocols are not. Delete the file when you are done.
+
+## Check what the application's identity can do
+
+```sh
+P=1; S=/proc/$P/root/var/run/secrets/kubernetes.io/serviceaccount
+alias ks='kubectl --server=https://kubernetes.default.svc --certificate-authority=$S/ca.crt --token="$(cat $S/token)"'
+ks auth can-i --list -n "$(cat $S/namespace)"
+```
+
+See [`kubectl`](tools/kubernetes.md#kubectl) for why this borrowing is needed.
+
+## Inspect Services and `kube-proxy` rules on a node
+
+```sh
+kubectl debug node/ -it --image=ghcr.io/ngpayyappilly/k8s-debug:latest --profile=sysadmin
+
+iptables -t nat -S KUBE-SERVICES | grep my-svc # the Service's entry rule
+iptables-save | grep -A5 'my-svc' # follow the chain to the endpoints
+iptables-legacy -t nat -S | head # if the above shows nothing
+nft list ruleset | grep my-svc # nftables mode
+conntrack -L -d # live connections and their chosen backend
+nsenter -t 1 -m -u -i -n -p -- journalctl -u kubelet --since '10 min ago'
+```
+
+See [`iptables`](tools/packets-firewall.md#iptables) for the nft versus legacy distinction.
+
+## Test a gRPC service
+
+```sh
+grpcurl -plaintext my-svc.my-ns.svc.cluster.local:50051 list
+grpcurl -plaintext my-svc:50051 grpc.health.v1.Health/Check
+grpcurl -plaintext -d '{"id": "42"}' my-svc:50051 my.pkg.Orders/Get
+```
+
+## Measure bandwidth between two pods
+
+```sh
+kubectl run iperf-server --image=ghcr.io/ngpayyappilly/k8s-debug:latest --restart=Never -- iperf3 -s
+IP=$(kubectl get pod iperf-server -o jsonpath='{.status.podIP}')
+# from the debug container in the pod under test:
+iperf3 -c $IP -t 10
+kubectl delete pod iperf-server
+```
+
+Run it same-node, cross-node and cross-zone, and compare. A big drop only when crossing nodes points at the
+overlay network or MTU.
diff --git a/docs/requirements.txt b/docs/requirements.txt
new file mode 100644
index 0000000..0c525b8
--- /dev/null
+++ b/docs/requirements.txt
@@ -0,0 +1,2 @@
+mkdocs==1.6.1
+mkdocs-material==9.7.7
diff --git a/docs/tools/connectivity.md b/docs/tools/connectivity.md
new file mode 100644
index 0000000..05987e2
--- /dev/null
+++ b/docs/tools/connectivity.md
@@ -0,0 +1,258 @@
+# HTTP and connectivity
+
+Tools for answering *can A reach B, and what happens when it does?* from inside the pod's network namespace.
+Because the debug container shares the pod's network, `localhost` is the app, and the pod's DNS, routes,
+NetworkPolicy and service mesh sidecar all apply to your commands exactly as they do to the app.
+
+## `curl`
+
+**Package:** `curl` · **Needs:** nothing special
+
+The default tool for HTTP, HTTPS and many other protocols. Use it to check an endpoint, see headers, and
+break a request into timing phases.
+
+```sh
+# Call a Service by its cluster DNS name, show request and response headers
+curl -sv http://my-svc.my-ns.svc.cluster.local:8080/healthz
+
+# Where does the time go? DNS, TCP connect, TLS, first byte, total
+curl -o /dev/null -s -w 'dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total}\n' \
+ https://my-svc.my-ns.svc.cluster.local/
+
+# Talk to one specific backend, ignoring DNS and load balancing
+curl --resolve my-svc.example.com:443:10.244.1.17 https://my-svc.example.com/
+
+# Same, but set the Host header instead (plain HTTP)
+curl -H 'Host: my-svc.example.com' http://10.244.1.17:8080/
+
+# Trust an internal CA
+curl --cacert /path/to/ca.crt https://internal.example.com/
+
+# Hit the app on localhost, the way a sidecar or probe would
+curl -s localhost:8080/metrics | head
+```
+
+Tip: `curl -w '%{http_code}\n' -o /dev/null -s ` is a quick liveness check in a loop:
+`while sleep 1; do curl -s -o /dev/null -w '%{http_code} ' ; done`.
+
+## `wget`
+
+**Package:** `wget` · **Needs:** nothing special
+
+A simpler downloader, useful when you want to save a file or when a script expects `wget`.
+
+```sh
+wget -qO- http://my-svc:8080/healthz # print the body
+wget --spider -S http://my-svc:8080/ # headers only, no download
+wget --no-check-certificate https://my-svc/ # skip TLS verification (diagnosis only)
+```
+
+## `nc`
+
+**Package:** `netcat-openbsd` · **Needs:** nothing special
+
+The OpenBSD `netcat`. The fastest way to test whether a TCP or UDP port accepts connections, without speaking
+any protocol.
+
+```sh
+# Is the port open? (-z scan only, -v verbose, -w timeout seconds)
+nc -zv -w 3 postgres.db.svc.cluster.local 5432
+
+# Several ports, or a range
+nc -zv -w 2 my-svc 80 443
+nc -zv -w 1 my-svc 8000-8100 2>&1 | grep succeeded
+
+# UDP (best effort, UDP has no handshake)
+nc -zvu -w 2 10.96.0.10 53
+
+# Send a raw HTTP request
+printf 'GET /healthz HTTP/1.0\r\nHost: my-svc\r\n\r\n' | nc -w 3 my-svc 8080
+
+# Listen on a port, for testing NetworkPolicy from the other side
+nc -l -p 9000
+```
+
+`nc` is this one. `ncat` (below) is a different program with extra features such as TLS.
+
+## `ncat`
+
+**Package:** `ncat` (from the Nmap project) · **Needs:** nothing special
+
+A feature-rich netcat. Choose it over `nc` when you need TLS, proxies, access control, or a listener that
+serves many clients.
+
+```sh
+# Connect with TLS and speak a protocol by hand
+ncat --ssl my-svc.my-ns.svc.cluster.local 443
+
+# Listener that stays up for many connections and echoes what it receives
+ncat -l -k 9000 --exec /bin/cat
+
+# Listen with TLS (self-signed certificate generated for you)
+ncat -l --ssl 9443
+
+# Connect through an HTTP proxy
+ncat --proxy proxy.example.com:3128 --proxy-type http target.example.com 443
+```
+
+## `socat`
+
+**Package:** `socat` · **Needs:** nothing special
+
+A multipurpose relay. It connects any two "addresses": TCP, UDP, Unix sockets, files, stdin, TLS, and more.
+
+```sh
+# Forward a port inside the pod (a quick relay; use to prove a path works)
+socat TCP-LISTEN:9000,fork,reuseaddr TCP:my-svc.my-ns.svc.cluster.local:80
+
+# Same, and print everything that passes through (-v), a poor man's proxy
+socat -v TCP-LISTEN:9000,fork TCP:my-svc:80
+
+# Talk to a Unix socket in the target container's filesystem
+socat - UNIX-CONNECT:/proc//root/var/run/app.sock
+
+# Interactive TCP client with line editing
+socat READLINE TCP:my-svc:6379
+```
+
+!!! note
+ A relay started here only exists inside this pod's network namespace. To reach it from your laptop use
+ `kubectl port-forward 9000` in another terminal.
+
+## `openssl`
+
+**Package:** `openssl` · **Needs:** nothing special
+
+TLS inspection: what certificate does a server present, is it valid, who issued it, when does it expire.
+
+```sh
+# What certificate does the server present? (-servername sets SNI, important behind shared IPs)
+openssl s_client -connect my-svc.my-ns.svc:443 -servername my-svc.example.com /dev/null \
+ | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
+
+# Will it expire within 7 days? (exit status 1 means yes)
+openssl s_client -connect my-svc:443 /dev/null | openssl x509 -noout -checkend 604800
+
+# Show the whole chain the server sends
+openssl s_client -connect my-svc:443 -showcerts # throughput
+iperf3 -c -R # reverse direction
+iperf3 -c -P 4 # 4 parallel streams
+iperf3 -c -u -b 100M # UDP at 100 Mbit/s, shows loss and jitter
+```
+
+Remember to `kubectl delete pod iperf-server` afterwards. Comparing same-node, cross-node and cross-zone
+results is a fast way to find an overlay-network or MTU problem.
+
+## `ping`
+
+**Package:** `iputils-ping` · **Needs:** `NET_RAW` (in the default capabilities)
+
+ICMP echo. Checks basic IP reachability and latency.
+
+```sh
+ping -c 4 10.244.2.9
+
+# Find the path MTU: increase -s until it fails with "message too long"
+ping -c 2 -M do -s 1472 10.244.2.9
+```
+
+!!! warning "Services do not answer ping"
+ A Service's ClusterIP is a virtual address handled by `kube-proxy` or the CNI, usually for TCP/UDP ports
+ only. `ping ` failing proves nothing. Ping pod IPs and node IPs, and use [`nc`](#nc)
+ or [`curl`](#curl) for Services. Many networks also drop ICMP.
+
+## `tracepath`
+
+**Package:** `iputils-tracepath` · **Needs:** nothing special
+
+Traces the path and reports the discovered **path MTU** at each hop, with no special permissions.
+
+```sh
+tracepath -n 10.244.2.9
+```
+
+A line such as `pmtu 1450` shows the effective MTU. If it is lower than your pod's `eth0` MTU, large packets
+will be dropped or fragmented (check with [`ip`](network-stack.md#ip)).
+
+## `traceroute`
+
+**Package:** `traceroute` · **Needs:** `NET_RAW` for ICMP and TCP modes
+
+Shows each router between you and a destination.
+
+```sh
+traceroute -n 8.8.8.8
+traceroute -n -T -p 443 example.com # TCP SYN probes, passes more firewalls
+traceroute -n -I example.com # ICMP probes
+```
+
+Inside a cluster you will typically see the node, then the node's gateway. Stars (`* * *`) mean a hop that
+does not answer, not necessarily a failure.
+
+## `mtr`
+
+**Package:** `mtr-tiny` · **Needs:** `NET_RAW`
+
+`traceroute` and `ping` combined: per-hop packet loss and latency over many probes. This build has no
+graphical interface, so use the report mode.
+
+```sh
+mtr -rwn -c 20 10.244.2.9 # report: 20 probes, wide, numeric
+mtr -rwn -T -P 443 -c 20 example.com # TCP probes to port 443
+```
+
+Read loss from the **last** hop. Loss in a middle hop that does not continue to the end is usually that router
+rate-limiting ICMP, not a real problem.
+
+## `nmap`
+
+**Package:** `nmap` · **Needs:** nothing special for TCP connect scans, `NET_RAW` for others
+
+A port scanner and service detector. Use it on systems you are authorised to test, and remember it generates a
+lot of traffic that may trip alerts.
+
+```sh
+# Which of these ports are open? (-Pn skips host discovery, -n skips DNS)
+nmap -Pn -n -p 80,443,8080 10.244.2.9
+
+# What is running on them?
+nmap -Pn -n -sV -p 1-1024 10.244.2.9
+
+# Inspect a TLS certificate and supported ciphers
+nmap -Pn -p 443 --script ssl-cert,ssl-enum-ciphers my-svc.my-ns.svc.cluster.local
+
+# Find hosts on a small range (e.g. who answers in a pod CIDR slice)
+nmap -sn 10.244.2.0/28
+```
+
+If `nc -zv` answers your question, use that. `nmap` is for when you do not know which port to ask about.
diff --git a/docs/tools/dns.md b/docs/tools/dns.md
new file mode 100644
index 0000000..095a066
--- /dev/null
+++ b/docs/tools/dns.md
@@ -0,0 +1,98 @@
+# DNS
+
+Most Kubernetes "network problems" are DNS problems. These tools query DNS directly so you can see what the
+resolver sees. Start by looking at the pod's resolver configuration:
+
+```sh
+cat /etc/resolv.conf
+```
+
+```text
+search my-ns.svc.cluster.local svc.cluster.local cluster.local
+nameserver 10.96.0.10
+options ndots:5
+```
+
+- `nameserver` is the cluster DNS Service (CoreDNS or kube-dns).
+- `search` lists the suffixes tried for short names.
+- `ndots:5` means any name with **fewer than 5 dots** is tried against every search suffix first. A lookup of
+ `api.example.com` (2 dots) can cost several failed queries before the real one. This is the usual cause of
+ slow or flaky external DNS in pods. See the [DNS recipe](../recipes.md#dns-is-slow-or-failing).
+
+!!! note
+ The ephemeral container is part of the pod, so it uses the pod's DNS settings. `/etc/resolv.conf` is the
+ same one the app uses.
+
+## `dig`
+
+**Package:** `dnsutils` (BIND tools) · **Needs:** nothing special
+
+The reference DNS client. It shows the full answer, flags, timing and which server replied.
+
+```sh
+# Resolve a Service
+dig my-svc.my-ns.svc.cluster.local
+
+# Just the answer
+dig +short my-svc.my-ns.svc.cluster.local
+
+# Ask a specific server (CoreDNS service IP, a node-local cache, or an upstream)
+dig @10.96.0.10 my-svc.my-ns.svc.cluster.local
+dig @8.8.8.8 example.com
+
+# Use the search list, as the app's resolver does (dig ignores it by default)
+dig +search my-svc
+
+# Headless Service: one A record per pod
+dig +short my-headless.my-ns.svc.cluster.local
+
+# SRV records (named ports)
+dig +short SRV _http._tcp.my-svc.my-ns.svc.cluster.local
+
+# Reverse lookup of a pod or service IP
+dig +short -x 10.244.2.9
+
+# Force TCP (tests whether large responses or TCP/53 are blocked)
+dig +tcp my-svc.my-ns.svc.cluster.local
+
+# Only the answer section plus query time, to measure latency
+dig +noall +answer +stats example.com
+
+# Walk the delegation from the root
+dig +trace example.com
+```
+
+Read the `status:` in the header: `NOERROR` with an empty answer means the name exists but has no record of that
+type; `NXDOMAIN` means it does not exist; `SERVFAIL` means the server could not answer (often an upstream
+problem). `;; connection timed out; no servers could be reached` means you cannot reach the DNS server at all.
+
+## `nslookup`
+
+**Package:** `dnsutils` · **Needs:** nothing special
+
+An older, simpler client. Unlike `dig` it **does** apply the search list, so it is handy for "does the short
+name work?".
+
+```sh
+nslookup kubernetes.default
+nslookup my-svc.my-ns 10.96.0.10 # optional server as the last argument
+nslookup -type=SRV _http._tcp.my-svc.my-ns.svc.cluster.local
+```
+
+`nslookup` prints `Server:` and `Address:` first. That is the resolver it used, so you can confirm which DNS
+server the pod is really talking to.
+
+## `drill`
+
+**Package:** `ldnsutils` · **Needs:** nothing special
+
+A `dig`-like tool from the `ldns` library with strong DNSSEC support.
+
+```sh
+drill example.com @10.96.0.10
+drill -T example.com # trace from the root
+drill -D example.com # request DNSSEC records
+drill -S example.com # chase DNSSEC signatures to the root
+```
+
+Use it when you need to debug DNSSEC validation. For everything else, [`dig`](#dig) is more familiar.
diff --git a/docs/tools/index.md b/docs/tools/index.md
new file mode 100644
index 0000000..7549d01
--- /dev/null
+++ b/docs/tools/index.md
@@ -0,0 +1,55 @@
+# Tools
+
+Every utility in the image, grouped by what you are trying to find out. Each section lists the Ubuntu
+package it comes from, the permissions it needs (see [Permissions](../getting-started/permissions.md)), and
+examples written for Kubernetes situations.
+
+| Page | Tools |
+|---|---|
+| [HTTP and connectivity](connectivity.md) | [`curl`](connectivity.md#curl) [`wget`](connectivity.md#wget) [`nc`](connectivity.md#nc) [`ncat`](connectivity.md#ncat) [`socat`](connectivity.md#socat) [`openssl`](connectivity.md#openssl) [`iperf3`](connectivity.md#iperf3) [`ping`](connectivity.md#ping) [`tracepath`](connectivity.md#tracepath) [`traceroute`](connectivity.md#traceroute) [`mtr`](connectivity.md#mtr) [`nmap`](connectivity.md#nmap) |
+| [DNS](dns.md) | [`dig`](dns.md#dig) [`nslookup`](dns.md#nslookup) [`drill`](dns.md#drill) |
+| [Network stack](network-stack.md) | [`ip`](network-stack.md#ip) [`ss`](network-stack.md#ss) [`arping`](network-stack.md#arping) [`ethtool`](network-stack.md#ethtool) [`ifconfig`](network-stack.md#ifconfig) [`netstat`](network-stack.md#netstat) [`brctl`](network-stack.md#brctl) |
+| [Packet capture and firewall](packets-firewall.md) | [`tcpdump`](packets-firewall.md#tcpdump) [`iptables`](packets-firewall.md#iptables) [`nft`](packets-firewall.md#nft) [`ipset`](packets-firewall.md#ipset) [`conntrack`](packets-firewall.md#conntrack) |
+| [Processes and system](processes.md) | [`ps`](processes.md#ps) [`pgrep`](processes.md#pgrep) [`top`](processes.md#top) [`free`](processes.md#free) [`vmstat`](processes.md#vmstat) [`htop`](processes.md#htop) [`lsof`](processes.md#lsof) [`fuser`](processes.md#fuser) [`pstree`](processes.md#pstree) [`pidstat`](processes.md#pidstat) [`iostat`](processes.md#iostat) [`mpstat`](processes.md#mpstat) [`iotop`](processes.md#iotop) [`strace`](processes.md#strace) [`ltrace`](processes.md#ltrace) [`gdb`](processes.md#gdb) [`bpftrace`](processes.md#bpftrace) [`nsenter`](processes.md#nsenter) [`lsns`](processes.md#lsns) [`findmnt`](processes.md#findmnt) [`dmesg`](processes.md#dmesg) [`lsmod`](processes.md#lsmod) [`lspci`](processes.md#lspci) |
+| [Kubernetes and data](kubernetes.md) | [`kubectl`](kubernetes.md#kubectl) [`stern`](kubernetes.md#stern) [`grpcurl`](kubernetes.md#grpcurl) [`yq`](kubernetes.md#yq) [`jq`](kubernetes.md#jq) |
+| [Shell and files](shell.md) | [`bash`](shell.md#bash) [`vi`](shell.md#vi) [`nano`](shell.md#nano) [`less`](shell.md#less) [`file`](shell.md#file) [`tree`](shell.md#tree) [`unzip`](shell.md#unzip) [`xz`](shell.md#xz) [`git`](shell.md#git) [`ssh`](shell.md#ssh) [`gpg`](shell.md#gpg) [`python3`](shell.md#python3) |
+
+## Conventions used in the examples
+
+- ``, ``, `` and similar are placeholders.
+- `` means a process ID **as seen from the debug container**. With `--target`, the app's processes are
+ visible, so find it with `pgrep` or `ps`. In most containers the app is PID 1.
+- `/proc//root` is the target container's filesystem. The shell helper `troot ` prints that path.
+- "Needs" lines describe the minimum. Where it says *nothing special*, the default profile is enough.
+
+## Tool versions
+
+The four standalone binaries are pinned in the [Dockerfile](https://github.com/ngpayyappilly/k8s-debug/blob/main/Dockerfile)
+and checksum verified. Everything else is whatever Ubuntu 24.04 ships.
+
+| Tool | Version |
+|---|---|
+| `kubectl` | v1.36.1 |
+| `yq` (mikefarah) | v4.47.1 |
+| `grpcurl` | 1.9.3 |
+| `stern` | 1.33.0 |
+
+For the exact version of any other tool in a given image tag:
+
+```sh
+docker run --rm --entrypoint dpkg ghcr.io/ngpayyappilly/k8s-debug: -l
+```
+
+## Not installed, and what to do instead
+
+The image favours tools that work in any pod. Language-specific profilers are not included because they must
+match the target runtime.
+
+| You want | Do this |
+|---|---|
+| Java thread or heap dumps | Use a JDK-based debug image, or `kubectl debug --copy-to` with the JDK image |
+| Go `pprof` / `delve` | Expose `net/http/pprof` and use `curl` to fetch profiles |
+| `perf` | Not usable from a container without matching kernel tools. Use [`bpftrace`](processes.md#bpftrace) or [`strace -c`](processes.md#strace) |
+| Wireshark GUI | Capture with [`tcpdump`](packets-firewall.md#tcpdump), stream the file out, open it locally ([recipe](../recipes.md#capture-traffic-and-open-it-in-wireshark)) |
+
+You can also build your own image on top of this one. See [Contributing](../contributing.md#extend-the-image-for-your-own-needs).
diff --git a/docs/tools/kubernetes.md b/docs/tools/kubernetes.md
new file mode 100644
index 0000000..e4fbec5
--- /dev/null
+++ b/docs/tools/kubernetes.md
@@ -0,0 +1,167 @@
+# Kubernetes and data
+
+Tools for talking to the cluster API, tailing logs, calling gRPC services and slicing JSON and YAML.
+
+## `kubectl`
+
+**Version:** v1.36.1 (checksum verified) · **Needs:** credentials, see below. Alias: `k`, with tab completion.
+
+The Kubernetes command-line client, available **inside** the debug container so you can query the cluster
+from the pod's own point of view: its network, its DNS, its NetworkPolicy.
+
+!!! important "No credentials by default"
+ An ephemeral container does **not** get the pod's service account token mounted, and there is no
+ kubeconfig. A bare `kubectl get pods` will fail with *Unauthorized* or *forbidden*. The environment does
+ contain the cluster address (`KUBERNETES_SERVICE_HOST`), but no identity.
+
+**Borrow the target container's service account** (needs `--target` and the default `SYS_PTRACE`):
+
+```sh
+P=$(pgrep -o ) # or 1
+S=/proc/$P/root/var/run/secrets/kubernetes.io/serviceaccount
+
+kubectl --server=https://kubernetes.default.svc \
+ --certificate-authority=$S/ca.crt \
+ --token="$(cat $S/token)" \
+ get pods -n "$(cat $S/namespace)"
+```
+
+This acts **as the application**, which is exactly what you want when asking *"can this pod's identity do X?"*:
+
+```sh
+alias ks='kubectl --server=https://kubernetes.default.svc --certificate-authority=$S/ca.crt --token="$(cat $S/token)"'
+ks auth can-i list secrets -n "$(cat $S/namespace)"
+ks auth can-i --list
+```
+
+If the pod does not mount a token (`automountServiceAccountToken: false`), there is nothing to borrow.
+Supply your own kubeconfig or token instead, for example `kubectl --token= ...`, and treat it as the
+secret it is: **an interactive session is recorded in the container logs**.
+
+Other uses:
+
+```sh
+kubectl get endpointslices -l kubernetes.io/service-name=my-svc # which pods back a Service?
+kubectl get pod -o wide # IP, node
+kubectl describe pod # events, probe failures
+kubectl logs --previous # logs of the crashed container
+kubectl get events --sort-by=.lastTimestamp | tail -20
+```
+
+`kubectl` supports one minor version of skew against the API server. If your cluster is further away than that,
+build a matching image (`--build-arg KUBECTL_VERSION=...`, see
+[Installation](../getting-started/installation.md#build-it-yourself)).
+
+## `stern`
+
+**Version:** 1.33.0 (checksum verified) · **Needs:** credentials (see [`kubectl`](#kubectl)) with `get`, `list`,
+`watch` on pods and `get` on `pods/log`
+
+Tails logs from **many pods and containers at once**, color-coded by pod. Ideal for a Deployment with many
+replicas or when a request crosses services.
+
+```sh
+stern my-app -n my-ns # every pod whose name matches "my-app"
+stern -l app=my-app -n my-ns --since 5m # by label, last 5 minutes
+stern my-app -c sidecar --tail 20 # one container, last 20 lines each
+stern my-app -i 'ERROR|WARN' -e healthz # include / exclude by regex
+stern my-app --timestamps -o raw # raw lines, add timestamps
+stern -A 'coredns|kube-dns' --namespace kube-system
+```
+
+## `grpcurl`
+
+**Version:** 1.9.3 (checksum verified) · **Needs:** nothing special
+
+`curl` for gRPC. If the server enables **reflection**, no `.proto` files are needed.
+
+```sh
+# What services does it expose?
+grpcurl -plaintext my-svc.my-ns.svc.cluster.local:50051 list
+
+# Methods of one service, and the shape of a message
+grpcurl -plaintext my-svc:50051 list my.pkg.Greeter
+grpcurl -plaintext my-svc:50051 describe my.pkg.HelloRequest
+
+# Call a method
+grpcurl -plaintext -d '{"name": "world"}' my-svc:50051 my.pkg.Greeter/SayHello
+
+# Standard health check
+grpcurl -plaintext my-svc:50051 grpc.health.v1.Health/Check
+
+# TLS: verify with a CA, or skip verification (diagnosis only)
+grpcurl -cacert ca.crt my-svc.example.com:443 list
+grpcurl -insecure my-svc.example.com:443 list
+
+# Without reflection, supply the proto
+grpcurl -plaintext -import-path ./protos -proto greeter.proto -d '{}' my-svc:50051 my.pkg.Greeter/SayHello
+```
+
+`-plaintext` means no TLS. If you get *tls: first record does not look like a TLS handshake*, you used TLS
+against a plaintext server. If you get a connection reset, the opposite. A mesh sidecar may be in the way, so
+check with [`ss`](network-stack.md#ss).
+
+## `yq`
+
+**Version:** mikefarah/yq v4.47.1 (checksum verified) · **Needs:** nothing special
+
+A `jq`-like processor for YAML (and also JSON, XML, TOML, CSV). Note this is the Go `yq` by Mike Farah, not
+the Python wrapper of the same name, so its syntax is different.
+
+```sh
+kubectl get pod -o yaml | yq '.spec.containers[].image'
+kubectl get deploy my-app -o yaml | yq '.spec.template.spec.containers[] | {"name": .name, "resources": .resources}'
+yq '.metadata.labels' manifest.yaml
+yq -i '.spec.replicas = 3' manifest.yaml # edit in place
+yq -o=json '.' values.yaml # convert YAML to JSON
+yq eval-all 'select(.kind == "Service") | .metadata.name' *.yaml # across many files / documents
+```
+
+## `jq`
+
+**Package:** `jq` · **Needs:** nothing special
+
+The standard JSON processor. `kubectl -o json` plus `jq` answers most "which of these..." questions.
+
+```sh
+# Pods that are not Running
+kubectl get pods -A -o json | jq -r '.items[] | select(.status.phase != "Running") | "\(.metadata.namespace)/\(.metadata.name) \(.status.phase)"'
+
+# Restart counts and last termination reason
+kubectl get pod -o json | jq '.status.containerStatuses[] | {name, restartCount, last: .lastState.terminated}'
+
+# Pods on a given node
+kubectl get pods -A -o json | jq -r --arg n node-1 '.items[] | select(.spec.nodeName == $n) | .metadata.name'
+
+# Decode every key of a Secret
+kubectl get secret my-secret -o json | jq -r '.data | map_values(@base64d)'
+
+# Pretty-print or filter an API response
+curl -s http://localhost:8080/status | jq '.errors[]?'
+```
+
+## Optional database clients
+
+Not in the published image. Build with `--build-arg INSTALL_DB_CLIENTS=true` to add them, useful for checking
+connectivity and credentials to a database from the application's own network position.
+
+### `redis-cli`
+
+```sh
+redis-cli -h redis.my-ns.svc.cluster.local -p 6379 ping
+redis-cli -h redis --tls --cacert ca.crt info clients
+```
+
+### `psql`
+
+```sh
+psql "host=postgres.my-ns.svc.cluster.local user=app dbname=app sslmode=require" -c 'select 1'
+```
+
+### `mysql`
+
+```sh
+mysql -h mysql.my-ns.svc.cluster.local -u app -p -e 'select 1'
+```
+
+Without those clients, [`nc -zv`](connectivity.md#nc) still tells you whether the port is reachable.
diff --git a/docs/tools/network-stack.md b/docs/tools/network-stack.md
new file mode 100644
index 0000000..aeafc00
--- /dev/null
+++ b/docs/tools/network-stack.md
@@ -0,0 +1,117 @@
+# Network stack
+
+Inspect the pod's interfaces, addresses, routes, sockets and neighbours. These all show the **pod's** network
+namespace (not the node's), unless you debug a node, in which case they show the node's.
+
+## `ip`
+
+**Package:** `iproute2` · **Needs:** nothing to read; `NET_ADMIN` to change anything
+
+The modern replacement for `ifconfig`, `route` and `arp`.
+
+```sh
+ip -br addr # brief: interface, state, addresses
+ip addr show eth0 # full detail, including MTU
+ip route # the routing table
+ip route get 10.96.0.10 # which route and source address would be used for this destination?
+ip neigh # ARP / neighbour table (is the next hop resolved?)
+ip -s link show eth0 # packet, error and drop counters
+ip -d link show eth0 # details, including veth peer information
+```
+
+What to look for:
+
+- **MTU.** `eth0` is often 1500 on the node but 1450 or lower in the pod with an overlay network (VXLAN,
+ Geneve, WireGuard). A mismatch causes hangs on large responses while small ones work.
+- **Errors and drops** in `ip -s link`. Rising `dropped` or `errors` point at the interface or CNI.
+- **`ip route get `** is the fastest way to see whether traffic would go out via `eth0`, a service mesh
+ interface, or nowhere.
+- **`ip neigh`** entries in `FAILED` or `INCOMPLETE` mean the next hop is not answering ARP.
+
+## `ss`
+
+**Package:** `iproute2` · **Needs:** nothing special. Process names need `--target` and, for other users'
+sockets, `SYS_PTRACE` (in the default profile).
+
+Socket statistics, a faster and more capable `netstat`.
+
+```sh
+ss -tulpn # listening TCP/UDP sockets and the process that owns each
+ss -tnp # established TCP connections with processes
+ss -s # summary: how many sockets in each state
+ss -tn state established '( dport = :5432 or sport = :5432 )' # connections to/from Postgres
+ss -tn state time-wait | wc -l # TIME_WAIT pile-up?
+ss -ti dst 10.244.2.9 # TCP internals: RTT, retransmits, congestion window
+ss -tlnp 'sport = :8080' # is anything listening on 8080?
+```
+
+- A `Recv-Q` that stays large on a LISTEN socket means the app is not calling `accept()` fast enough.
+- A large `Send-Q` on an established connection means the peer is not reading or the network is stalled.
+- Many `CLOSE-WAIT` sockets mean the app is not closing connections after the peer did (a leak in the app).
+- `ss -ti` fields such as `retrans` and `rtt` show whether a path is lossy or slow.
+
+## `arping`
+
+**Package:** `arping` · **Needs:** `NET_RAW`
+
+Sends ARP requests at layer 2. Use it when `ping` fails and you want to know if the neighbour exists at all, or
+to detect a duplicate IP address.
+
+```sh
+arping -I eth0 -c 3 10.244.2.1 # does the gateway answer ARP?
+arping -D -I eth0 -c 2 10.244.2.9 # duplicate address detection for your own IP
+```
+
+ARP only works within one L2 segment. Many CNIs route at L3, so a non-answer from a remote pod is normal.
+
+## `ethtool`
+
+**Package:** `ethtool` · **Needs:** nothing to read; `NET_ADMIN` to change
+
+Driver and hardware-level details of an interface.
+
+```sh
+ethtool -i eth0 # driver (veth, virtio_net, ena, ...)
+ethtool -S eth0 # NIC statistics, including drops and queue counters
+ethtool -S eth0 | grep peer_ifindex # for a veth: the index of the other end on the node
+ethtool -k eth0 # offload features (checksum, TSO, GRO)
+```
+
+`peer_ifindex` is the number to look for in `ip link` **on the node** (via a node debug session) to find which
+host interface belongs to this pod. Not every driver exposes the counters you want inside a container.
+
+## `ifconfig`
+
+**Package:** `net-tools` · **Needs:** nothing special
+
+The legacy interface viewer. It is installed for muscle memory and for scripts. Prefer [`ip`](#ip).
+
+```sh
+ifconfig eth0
+```
+
+## `netstat`
+
+**Package:** `net-tools` · **Needs:** nothing special
+
+Legacy socket listing. Prefer [`ss`](#ss), which is faster and shows more. `net-tools` also provides `route`
+and `arp`.
+
+```sh
+netstat -tulpn
+netstat -rn # routing table
+```
+
+## `brctl`
+
+**Package:** `bridge-utils` · **Needs:** nothing special to read
+
+Lists Linux bridges. A pod's own namespace usually has none. It is most useful on a **node** session, where
+CNIs such as `bridge`, Flannel and kind attach pod veths to a bridge.
+
+```sh
+brctl show # bridges and their attached interfaces
+```
+
+For modern bridge inspection also use `ip link show type bridge` and `bridge link`, which are part of
+`iproute2`.
diff --git a/docs/tools/packets-firewall.md b/docs/tools/packets-firewall.md
new file mode 100644
index 0000000..d2a4457
--- /dev/null
+++ b/docs/tools/packets-firewall.md
@@ -0,0 +1,124 @@
+# Packet capture and firewall
+
+Look at the actual packets, and at the kernel rules that route and filter them.
+
+## `tcpdump`
+
+**Package:** `tcpdump` · **Needs:** `NET_RAW`, which is in the default capabilities. Promiscuous mode needs
+`NET_ADMIN`, so add `-p` to avoid it.
+
+Captures packets on an interface and prints or saves them. Because you share the pod's network namespace, you
+see exactly the traffic the app sends and receives, including loopback traffic between the app and a sidecar.
+
+```sh
+# Everything, all interfaces, numeric, no promiscuous mode
+tcpdump -i any -nn -p
+
+# One port, or one peer
+tcpdump -i any -nn -p port 53
+tcpdump -i any -nn -p host 10.244.2.9 and tcp port 8080
+
+# Show HTTP request lines and bodies (plain HTTP only; TLS is encrypted)
+tcpdump -i any -nn -p -A -s0 'tcp port 8080'
+
+# Connection problems: SYNs and resets
+tcpdump -i any -nn -p 'tcp[tcpflags] & (tcp-syn|tcp-rst) != 0'
+
+# DNS queries and answers
+tcpdump -i any -nn -p -vv port 53
+
+# Stop after 100 packets
+tcpdump -i any -nn -p -c 100 port 8080
+
+# Save a capture to analyse later in Wireshark
+tcpdump -i any -nn -p -s0 -w /tmp/capture.pcap 'port 8080'
+```
+
+Getting a capture file out of the pod is covered in the
+[Wireshark recipe](../recipes.md#capture-traffic-and-open-it-in-wireshark).
+
+Reading the output: `Flags [S]` is a SYN, `[S.]` a SYN-ACK, `[.]` an ACK, `[P.]` data, `[F.]` a FIN and `[R]` a
+reset. A SYN with no SYN-ACK means the packet is being dropped or not answered (firewall, NetworkPolicy, wrong
+IP). A `[R.]` straight back means nothing is listening on that port.
+
+!!! note "Interface names"
+ `-i any` is the right default. With some CNIs and service meshes traffic also appears on extra interfaces
+ or on `lo`. Capturing on `any` (cooked capture) shows all of them but without Ethernet headers.
+
+## `iptables`
+
+**Package:** `iptables` · **Needs:** `NET_ADMIN` (use the `netadmin` profile, or `sysadmin` on a node)
+
+Lists and changes IPv4 packet-filter and NAT rules. In an ordinary pod this table is almost empty. It becomes
+interesting in two places:
+
+- **Service meshes** (Istio, Linkerd) install redirect rules in the pod's namespace.
+- **On a node**, `kube-proxy` (in iptables mode) implements Services with rules in the `nat` table.
+
+```sh
+iptables -t nat -L -n -v # NAT rules with packet counters
+iptables -t nat -S KUBE-SERVICES | head # (node) Service entry points
+iptables-save | grep my-svc # (node) every rule mentioning a Service
+iptables -t nat -L PREROUTING -n -v # (pod with a mesh) redirect rules
+```
+
+!!! warning "Two variants: nft and legacy"
+ Linux has two iptables back ends. `iptables` in this image is the **nft** variant; `iptables-legacy` is
+ also installed. A node's rules are only visible through the variant its components use.
+ If `iptables -t nat -S` shows nothing on a node that obviously has Services, try:
+
+ ```sh
+ iptables-legacy -t nat -S | head
+ ```
+
+ The same applies to `ip6tables` and `ip6tables-legacy`. The `nft list ruleset` command below shows
+ everything in the nft back end, whichever tool created it.
+
+## `nft`
+
+**Package:** `nftables` · **Needs:** `NET_ADMIN`
+
+The native interface to nftables. Newer clusters can run `kube-proxy` in nftables mode, and many CNIs and
+distributions use nftables directly. It also shows rules created through `iptables-nft`.
+
+```sh
+nft list tables
+nft list ruleset | less
+nft list chain ip nat PREROUTING
+nft list ruleset | grep my-svc
+```
+
+## `ipset`
+
+**Package:** `ipset` · **Needs:** `NET_ADMIN`
+
+Lists kernel IP sets: large collections of addresses that firewall rules match against. `kube-proxy` in IPVS
+mode and several network-policy engines (for example Calico) use them.
+
+```sh
+ipset list -name # names of all sets
+ipset list KUBE-CLUSTER-IP # members of one set
+ipset test KUBE-CLUSTER-IP 10.96.0.10
+```
+
+## `conntrack`
+
+**Package:** `conntrack` · **Needs:** `NET_ADMIN`
+
+The kernel's connection tracking table. NAT for Services is stateful, so this table is where you see which
+backend a connection was really sent to, and whether the table is full.
+
+```sh
+conntrack -L | head # all tracked connections
+conntrack -L -p tcp --dport 8080 # only those to port 8080
+conntrack -L -d 10.96.0.15 # connections to a Service ClusterIP (shows the DNAT'd backend)
+conntrack -C # how many entries now
+conntrack -S # per-CPU statistics: look at insert_failed and drop
+conntrack -E # watch events live
+```
+
+Compare the count to the limit on the node:
+`cat /proc/sys/net/netfilter/nf_conntrack_max`. If the table is full the kernel logs
+*nf_conntrack: table full, dropping packet* and new connections fail intermittently. A rising `insert_failed` in
+`conntrack -S` is the same problem showing up as a counter. In a pod you see the namespace's view. On a node you
+see all connections.
diff --git a/docs/tools/processes.md b/docs/tools/processes.md
new file mode 100644
index 0000000..751c749
--- /dev/null
+++ b/docs/tools/processes.md
@@ -0,0 +1,383 @@
+# Processes and system
+
+Find out what the app is doing, what it is waiting on, and what the kernel thinks about it.
+
+!!! important "Start with `--target`"
+ Without `--target=` you share only the pod's **network**. Add it and the target container's
+ processes appear in `ps`, and you can reach its filesystem, environment and limits through `/proc`:
+
+ ```sh
+ P=$(pgrep -o ) # or just 1, the app is usually PID 1
+ ls /proc/$P/root/ # its filesystem
+ tr '\0' '\n' < /proc/$P/environ # its environment variables
+ cat /proc/$P/cmdline | tr '\0' ' ' # how it was started
+ cat /proc/$P/limits # ulimits (open files, processes)
+ ls /proc/$P/fd | wc -l # how many file descriptors it holds
+ cat /proc/$P/root/sys/fs/cgroup/cpu.max /proc/$P/root/sys/fs/cgroup/memory.max # its limits
+ ```
+
+ The helper `troot ` prints `/proc//root`. Reading another user's process needs `SYS_PTRACE`,
+ which the default profile has.
+
+!!! note "User names come from this image"
+ `ps` and `ls -l` translate numeric IDs using **this image's** `/etc/passwd`, not the target's. A
+ process running as UID 101 may be shown as `tcpdump`. Use numeric IDs (`ps -eo pid,uid,comm`) when it
+ matters.
+
+## `ps`
+
+**Package:** `procps` · **Needs:** nothing special (`--target` to see the app)
+
+```sh
+ps auxf # all processes, as a tree
+ps -eo pid,ppid,uid,stat,%cpu,%mem,rss,etime,cmd # custom columns
+ps -eo pid,%cpu,%mem,cmd --sort=-%cpu | head # top CPU users
+ps -eo pid,rss,cmd --sort=-rss | head # top memory users
+ps -o pid,nlwp,cmd -p # thread count of one process
+ps -eo stat,pid,cmd | awk '$1 ~ /^Z/' # zombie processes
+```
+
+`STAT` letters: `R` running, `S` sleeping, `D` uninterruptible I/O wait (often a stuck disk or NFS mount),
+`Z` zombie (the parent never reaped it).
+
+## `pgrep`
+
+**Package:** `procps` · **Needs:** nothing special
+
+```sh
+pgrep -a nginx # PIDs and command lines matching a name
+pgrep -o java # the oldest match, usually the main process
+pgrep -f 'my-app --port' # match the full command line
+```
+
+`pkill` from the same package sends signals by name. Be careful: a signal reaches the **target** container's
+processes too.
+
+## `top`
+
+**Package:** `procps` · **Needs:** nothing special
+
+```sh
+top # interactive; press 1 for per-CPU, H for threads, c for full command
+top -b -n 1 | head -20 # one snapshot, handy for logs
+top -H -p # threads of one process
+```
+
+!!! warning "CPU and memory totals are the node's"
+ `top`, `free` and `/proc/meminfo` report the **node's** resources, not the container's limits. To know
+ what the app may use, read its cgroup (see the box at the top of this page).
+
+## `free`
+
+**Package:** `procps` · **Needs:** nothing special
+
+```sh
+free -m
+```
+
+Shows node memory (see the warning under [`top`](#top)). For the container's real limit and usage, look in its
+cgroup:
+
+```sh
+cat /proc/$P/root/sys/fs/cgroup/memory.max # the limit ("max" means unlimited)
+cat /proc/$P/root/sys/fs/cgroup/memory.current # current use
+cat /proc/$P/root/sys/fs/cgroup/memory.events # oom and oom_kill counters
+```
+
+## `vmstat`
+
+**Package:** `procps` · **Needs:** nothing special
+
+```sh
+vmstat 1 5
+```
+
+Five one-second samples of node-wide activity. Read `r` (runnable processes, compare to CPU count), `b`
+(blocked), `si`/`so` (swapping), `wa` (CPU time waiting on I/O).
+
+## `htop`
+
+**Package:** `htop` · **Needs:** nothing special
+
+A friendlier interactive process viewer. Needs a terminal, so use `kubectl debug -it`.
+
+```sh
+htop
+htop -p , # only these processes
+```
+
+`F5` toggles tree view, `F4` filters, `F2` setup (add columns such as `IO_RATE`), `t` toggles tree, `H` hides
+user threads.
+
+## `lsof`
+
+**Package:** `lsof` · **Needs:** `SYS_PTRACE` to see other users' processes
+
+Lists open files, and in Unix everything is a file: sockets, pipes, devices, directories.
+
+```sh
+lsof -p # everything one process has open
+lsof -nP -iTCP -sTCP:LISTEN # listening TCP sockets with process
+lsof -nP -i :8080 # who uses port 8080?
+lsof -nP -iTCP -sTCP:ESTABLISHED -a -p # its live connections
+lsof +L1 # deleted files that are still open (disk space not freed)
+lsof -p | wc -l # rough descriptor count; compare with `cat /proc//limits`
+```
+
+A steadily growing descriptor count is a leak. Many entries of one type (for example `sock`) show what kind.
+`lsof +L1` finds the classic "disk is full but I deleted the big file" case: a process still holds it open.
+
+## `fuser`
+
+**Package:** `psmisc` · **Needs:** `SYS_PTRACE` for other users' processes
+
+Shows which processes use a file, directory or port.
+
+```sh
+fuser -v 8080/tcp # who is listening on 8080?
+fuser -vm /proc/$P/root/data # who is using this mount?
+```
+
+`psmisc` also provides `killall` and [`pstree`](#pstree).
+
+## `pstree`
+
+**Package:** `psmisc` · **Needs:** nothing special
+
+```sh
+pstree -p # process tree with PIDs
+pstree -ap # a subtree with command-line arguments
+```
+
+## `pidstat`
+
+**Package:** `sysstat` · **Needs:** nothing special
+
+Per-process statistics over time, which `top` cannot give you in a script-friendly form.
+
+```sh
+pidstat -u -p 1 5 # CPU of one process, 5 samples
+pidstat -r -p 1 5 # memory: page faults, RSS
+pidstat -d -p 1 5 # disk I/O per process
+pidstat -w -p 1 5 # context switches (many "nvcswch" = CPU contention)
+pidstat -t -p 1 5 # per-thread
+```
+
+`pidstat -d` is the practical stand-in for [`iotop`](#iotop) in containers.
+
+## `iostat`
+
+**Package:** `sysstat` · **Needs:** nothing special
+
+Disk I/O for the whole node (block devices).
+
+```sh
+iostat -xz 1 5
+```
+
+`%util` near 100 and a high `await` mean the disk is saturated. Remember you see **node** devices, not only the
+pod's volumes.
+
+## `mpstat`
+
+**Package:** `sysstat` · **Needs:** nothing special
+
+Per-CPU utilisation.
+
+```sh
+mpstat -P ALL 1 5
+```
+
+One CPU at 100% while the rest idle points at a single-threaded bottleneck. High `%steal` in a VM means the
+hypervisor is taking CPU away. High `%iowait` means processes are waiting for disk.
+
+## `iotop`
+
+**Package:** `iotop-c` · **Needs:** `sysadmin` profile, and the kernel setting `task_delayacct`
+
+Live per-process disk I/O.
+
+```sh
+iotop -oPa # only active processes, accumulated
+iotop -b -n 1 -o # batch mode, one snapshot
+```
+
+It frequently prints `Warning: task_delayacct is 0`. Enable it on the node with
+`echo 1 > /proc/sys/kernel/task_delayacct` (or boot with `delayacct`), or use [`pidstat -d`](#pidstat) instead,
+which needs neither.
+
+## `strace`
+
+**Package:** `strace` · **Needs:** `SYS_PTRACE` (default profile)
+
+Prints the system calls a process makes. When an app hangs, fails mysteriously or is slow, this shows what it
+is asking the kernel to do and what the kernel answered.
+
+```sh
+strace -f -tt -T -p # follow threads, timestamps, time per call
+strace -f -p -e trace=network # only network calls
+strace -f -p -e trace=file # only file-related calls (finds missing config files: ENOENT)
+strace -f -p -e trace=openat,connect -s 256 # specific calls, longer strings
+strace -c -f -p # summary table of calls, errors and time; Ctrl-C to print
+strace -f -o /tmp/strace.out -p # write to a file
+```
+
+Common findings: `connect(...) = -1 ECONNREFUSED`, `openat(...) = -1 ENOENT` for a missing file,
+a thread stuck in `futex(...)` (waiting on a lock) or `read(...)` / `epoll_wait(...)` (waiting for I/O or events).
+
+!!! warning "It slows the target down"
+ `strace` stops the process at every system call. On a busy production process this can cause timeouts and
+ failed health probes. Filter with `-e trace=...`, use `-c`, attach briefly, or prefer
+ [`bpftrace`](#bpftrace) for high-rate processes.
+
+## `ltrace`
+
+**Package:** `ltrace` · **Needs:** `SYS_PTRACE`
+
+Like `strace`, but for **library** calls (for example `malloc`, `getaddrinfo`, `SSL_read`).
+
+```sh
+ltrace -f -p -e getaddrinfo # which hostnames is it resolving?
+ltrace -c -p # call summary
+```
+
+Works for dynamically linked programs using glibc. It does not work on statically linked binaries, and Go
+programs do not use the C library for most work, so for those use [`strace`](#strace).
+
+## `gdb`
+
+**Package:** `gdb` · **Needs:** `SYS_PTRACE`
+
+The GNU debugger. For a live process you most often want a stack dump of every thread.
+
+```sh
+# One-shot stack of all threads, then detach (the process resumes)
+gdb -p -batch -ex 'thread apply all bt' -ex detach
+
+# Interactive
+gdb -p
+(gdb) info threads
+(gdb) thread apply all bt
+(gdb) detach
+(gdb) quit
+
+# Analyse a core file with the binary that produced it
+gdb /proc/$P/root/usr/local/bin/app /path/to/core
+```
+
+!!! warning "Attaching pauses the process"
+ The process is stopped while `gdb` is attached. Detach promptly or a liveness probe may kill the pod. Stack
+ traces are readable only if the binary has symbols. Stripped binaries show addresses.
+
+## `bpftrace`
+
+**Package:** `bpftrace` · **Needs:** the `sysadmin` profile (eBPF needs `SYS_ADMIN`/`BPF`/`PERFMON`) and a
+kernel with eBPF and BTF
+
+A scripting language for eBPF: low-overhead tracing of the kernel and applications without stopping them.
+
+```sh
+# Check it works
+bpftrace -e 'BEGIN { printf("ok\n"); exit(); }'
+
+# Every file opened, with the process that opened it
+bpftrace -e 'tracepoint:syscalls:sys_enter_openat { printf("%s %s\n", comm, str(args->filename)); }'
+
+# Count system calls per process for 10 seconds
+bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); } interval:s:10 { exit(); }'
+
+# New TCP connections (kernel function probe)
+bpftrace -e 'kprobe:tcp_connect { printf("%s connecting\n", comm); }'
+
+# List available probes
+bpftrace -l 'tracepoint:syscalls:sys_enter_*' | head
+```
+
+Requires a privileged container, so use `--profile=sysadmin`. Many managed clusters and hardened namespaces
+forbid that. If it fails with permission errors, [`strace`](#strace) is the fallback.
+
+## `nsenter`
+
+**Package:** `util-linux` · **Needs:** `sysadmin` profile (`SYS_ADMIN` and `SYS_PTRACE`)
+
+Runs a command inside another process's namespaces. Most useful in a **node** session, where you can step into
+a container or into the node itself.
+
+```sh
+# From a node debug session: become the node (PID 1's namespaces) and use its own tools
+nsenter -t 1 -m -u -i -n -p -- systemctl status kubelet
+nsenter -t 1 -m -u -i -n -p -- journalctl -u kubelet --since '10 min ago'
+
+# Run a command in a container's network namespace (find the PID on the node first)
+nsenter -t -n ip addr
+```
+
+In an ordinary pod session you already share the pod's network namespace, so you rarely need it.
+
+## `lsns`
+
+**Package:** `util-linux` · **Needs:** nothing special
+
+Lists namespaces and which process owns each, for understanding what you share with whom.
+
+```sh
+lsns
+lsns -t net # network namespaces only
+```
+
+If the pod and a process share a network namespace ID, they share an IP address.
+
+## `findmnt`
+
+**Package:** `util-linux` · **Needs:** nothing special
+
+Shows mounts as a tree, with options. Good for checking whether a volume is mounted, read-only, or on the
+right filesystem.
+
+```sh
+findmnt # this container's mounts
+findmnt -R /proc/$P/root # (node) mounts beneath a container root, if visible
+findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS /host/var/lib/kubelet/pods
+```
+
+For the **app's** view of mounts, read `cat /proc/$P/mountinfo`.
+
+## `dmesg`
+
+**Package:** `util-linux` · **Needs:** `sysadmin` profile (`SYSLOG` on many kernels)
+
+The kernel ring buffer: OOM kills, hardware errors, filesystem errors, conntrack table messages, network
+driver resets.
+
+```sh
+dmesg -T | tail -50 # human-readable timestamps
+dmesg -T | grep -i -E 'oom|killed process' # OOM kills
+dmesg -T | grep -i conntrack
+```
+
+An OOM kill here (`Out of memory: Killed process ...`) confirms a container exceeded its memory limit, whatever
+the application logged.
+
+## `lsmod`
+
+**Package:** `kmod` · **Needs:** nothing special
+
+Lists loaded kernel modules, read from `/proc/modules`.
+
+```sh
+lsmod | grep -E 'conntrack|ip_vs|overlay|wireguard|vxlan'
+```
+
+Check whether a module your CNI or `kube-proxy` mode needs (such as `nf_conntrack`, `ip_vs`, `vxlan`) is loaded.
+Loading modules (`modprobe`) needs `sysadmin` and is rarely what you want in production.
+
+## `lspci`
+
+**Package:** `pciutils` · **Needs:** nothing special
+
+Lists PCI devices. Mostly relevant on **node** sessions for GPU, SR-IOV or high-performance NIC problems.
+
+```sh
+lspci
+lspci -k | grep -A3 -i -E 'ethernet|nvidia' # devices with their kernel drivers
+```
diff --git a/docs/tools/shell.md b/docs/tools/shell.md
new file mode 100644
index 0000000..3d97507
--- /dev/null
+++ b/docs/tools/shell.md
@@ -0,0 +1,175 @@
+# Shell and files
+
+The environment you work in, plus general-purpose utilities.
+
+## `bash`
+
+**Package:** `bash`, `bash-completion` · **Needs:** nothing special
+
+The default shell (it is the image's entrypoint). The configuration in `/root/.bashrc` gives you:
+
+| Feature | Detail |
+|---|---|
+| Banner | A summary of the tools and `--target` tips, shown once per interactive shell |
+| Prompt | `[debug] : #` |
+| `k` | Alias for `kubectl`, with tab completion |
+| `troot ` | Prints `/proc//root`, the target container's filesystem: `ls $(troot 1)/etc` |
+| `ll` | `ls -alF` |
+| History | 5000 lines, kept for the session only (the container's disk is ephemeral) |
+| `vim` | Alias for `vi` |
+
+Tab completion works for `kubectl` and for commands and file names. Run one-off commands without a shell by
+passing them to `kubectl debug`:
+
+```sh
+kubectl debug -it --image=ghcr.io/ngpayyappilly/k8s-debug:latest --target= -- tcpdump -i any -nn -p port 53
+```
+
+!!! tip "Capturing the output of a short command"
+ If a command finishes before `kubectl debug` attaches, you see no output. The output is still saved:
+ `kubectl logs -c `. Give the container a name with `--container=` so
+ you can find it.
+
+## `vi`
+
+**Package:** `vim-tiny` · **Needs:** nothing special
+
+A small `vi`. The `vim` command is an alias to it. Syntax highlighting and plugins are not included, which is
+fine for editing a config file. `i` to insert, `Esc` then `:wq` to save and quit, `:q!` to quit without saving.
+
+Remember that the debug container's filesystem is separate from the app's. To edit a file the **app** reads, you
+can go through `/proc//root/...`, but only if that path is on a writable volume, and changes are lost when the
+pod restarts.
+
+## `nano`
+
+**Package:** `nano` · **Needs:** nothing special
+
+An easier editor if you do not know `vi`. `Ctrl-O` saves, `Ctrl-X` exits.
+
+## `less`
+
+**Package:** `less` · **Needs:** nothing special
+
+A pager for long output and files.
+
+```sh
+less /proc/$P/root/var/log/app.log # read the app's log file
+dmesg -T | less
+less +F /proc/$P/root/var/log/app.log # follow like `tail -f`; Ctrl-C to stop following, F to resume
+```
+
+Inside `less`: `/text` searches, `n` repeats, `G` goes to the end, `q` quits.
+
+## `file`
+
+**Package:** `file` · **Needs:** nothing special
+
+Identifies what a file is, based on its contents. Useful for telling a script from a binary, or checking
+architecture and linkage before you debug it.
+
+```sh
+file /proc/$P/root/usr/local/bin/app
+```
+
+```text
+ELF 64-bit LSB executable, ARM aarch64, ... statically linked, stripped
+```
+
+*Stripped* means no symbols (poor `gdb` stack traces). *Statically linked* means [`ltrace`](processes.md#ltrace)
+will not work on it. If the architecture differs from the node's, you have the wrong image.
+
+## `tree`
+
+**Package:** `tree` · **Needs:** nothing special
+
+```sh
+tree -L 2 /proc/$P/root/app # two levels deep
+tree -a -L 3 /proc/$P/root/etc/nginx
+```
+
+## `unzip`
+
+**Package:** `unzip` · **Needs:** nothing special
+
+```sh
+unzip -l artifact.jar # list the contents of a jar/zip without extracting
+unzip -p app.jar META-INF/MANIFEST.MF # print one file
+```
+
+`tar`, `gzip` and `bzip2` are part of the base system. See also [`xz`](#xz).
+
+## `xz`
+
+**Package:** `xz-utils` · **Needs:** nothing special
+
+```sh
+xz -dc dump.sql.xz | head # read a compressed file without unpacking
+tar -xJf bundle.tar.xz
+```
+
+## `git`
+
+**Package:** `git` · **Needs:** nothing special
+
+Clone configuration repositories, compare manifests, or bisect a config change from inside the cluster
+network, for example to reach an internal Git server the cluster can see but your laptop cannot.
+
+```sh
+git clone https://git.internal.example.com/team/config.git
+git diff --no-index /proc/$P/root/etc/app/config.yaml ./config.yaml
+```
+
+`git diff --no-index` compares any two files, whether or not they are in a repository.
+
+## `ssh`
+
+**Package:** `openssh-client` · **Needs:** nothing special
+
+An SSH client, including `scp` and `ssh-keygen`. Use it to test connectivity to a bastion or SFTP server from the
+pod's network position.
+
+```sh
+ssh -v -o BatchMode=yes -o ConnectTimeout=5 user@host true # verbose connect test, no prompts
+scp user@host:/path/file .
+ssh-keyscan -t ed25519 host # fetch a host key
+```
+
+Never bake private keys into images, and avoid typing passphrases in a recorded session.
+
+## `gpg`
+
+**Package:** `gnupg` · **Needs:** nothing special
+
+Verify signatures and decrypt files, for example release artifacts or encrypted secrets.
+
+```sh
+gpg --verify artifact.tar.gz.asc artifact.tar.gz
+gpg --list-keys
+```
+
+## `python3`
+
+**Package:** `python3` · **Needs:** nothing special
+
+The Python 3 standard library, with no extra packages. Handy for quick scripts when no other tool does the job.
+
+```sh
+# Serve this container's directory over HTTP, to copy a file to another pod or laptop quickly
+python3 -m http.server 8000
+
+# TCP reachability check with a timeout, anywhere `nc` is blocked
+python3 -c "import socket; socket.create_connection(('my-svc', 5432), 3); print('open')"
+
+# Pretty-print JSON
+curl -s localhost:8080/status | python3 -m json.tool
+
+# Resolve a name through the pod's resolver, exactly as a Python app would
+python3 -c "import socket; print(socket.getaddrinfo('my-svc.my-ns', 80))"
+```
+
+!!! note "Also in the base system"
+ `ca-certificates` provides the trusted CA bundle, so `curl` and `openssl` trust public sites. To trust an
+ internal CA, copy it to `/usr/local/share/ca-certificates/` with a `.crt` extension and run
+ `update-ca-certificates`. The standard coreutils (`base64`, `sha256sum`, `dd`, `timeout`, `watch`, `sort`,
+ `awk`, `sed`, `grep`) are all present.
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
new file mode 100644
index 0000000..abad317
--- /dev/null
+++ b/docs/troubleshooting.md
@@ -0,0 +1,123 @@
+# Troubleshooting
+
+When `kubectl debug` or the tools themselves do not behave.
+
+## Starting a session
+
+### `error: ephemeral containers are disabled for this cluster` or the flag is unknown
+
+Your cluster is older than 1.25, or an administrator disabled the feature, or your `kubectl` is too old. Check
+both:
+
+```sh
+kubectl version
+```
+
+### `forbidden: ... cannot patch resource "pods/ephemeralcontainers"`
+
+You lack RBAC for it. See [RBAC](getting-started/permissions.md#rbac-what-you-need-to-be-allowed-to-do).
+
+### The container shows `ImagePullBackOff` or `ErrImagePull`
+
+```sh
+kubectl describe pod | grep -A5 -i ephemeral
+```
+
+- The node cannot reach `ghcr.io`. Mirror the image
+ ([Installation](getting-started/installation.md#private-clusters-and-air-gapped-registries)).
+- The tag does not exist. `latest` only exists once a stable version has been released. Use `edge` or an exact
+ `X.Y.Z`.
+- Platform mismatch is not an issue: the image is published for amd64 and arm64.
+
+### `CreateContainerConfigError: container has runAsNonRoot and image will run as root`
+
+The pod or profile requires a non-root user and this image does not set one. Pass a numeric user with
+`--custom`. See [Pods that run as non-root](getting-started/permissions.md#pods-that-run-as-non-root).
+
+### Admission rejects the container (`violates PodSecurity`)
+
+The namespace enforces the Baseline or Restricted Pod Security Standard and you asked for more than it allows,
+for example `sysadmin`. Use a less privileged profile (`general`, `baseline` or `restricted`). If you need more
+privilege than that namespace allows, ask a cluster administrator, or reproduce the problem in a namespace
+that permits it.
+
+### I get a prompt but nothing seems to run, or the output is empty
+
+For short one-shot commands the container may finish before your terminal attaches. Read the output from the
+logs:
+
+```sh
+kubectl debug --container=probe --image=... --target= -- dig +short my-svc
+kubectl logs -c probe
+```
+
+### The session ended and I cannot get back in
+
+If the shell exited, the container is `Terminated`. Ephemeral containers cannot be restarted or deleted, so
+start a new one (a new name). If you only lost your terminal and the container is still running, re-attach:
+
+```sh
+kubectl attach -it -c
+```
+
+## Inside the container
+
+### `ps` shows only my own processes
+
+You started without `--target`, or the container runtime does not support shared process namespaces for
+ephemeral containers. `kubectl` prints a warning: *Targeting container ... If you don't see processes from
+this container it may be because the container runtime doesn't support this feature.* For a pod you can
+restart, `shareProcessNamespace: true` on the pod spec is the supported alternative, or debug a copy with
+`--copy-to ... --share-processes`.
+
+### `Operation not permitted` from `strace`, `gdb`, or reading `/proc//...`
+
+You lack `SYS_PTRACE`. The default (`general`) profile has it, but `netadmin` does not and a non-root pod
+removes everything. See [Permissions](getting-started/permissions.md). Also check that you really are in the same
+process namespace as the target (`--target`).
+
+### `tcpdump: You don't have permission to perform this capture on that device`
+
+You have no `NET_RAW`. This usually means the pod runs as a non-root user and the debug container inherited that.
+Override with `--custom` (see [non-root pods](getting-started/permissions.md#pods-that-run-as-non-root)).
+
+### `kubectl` says `Unauthorized` or `forbidden` from inside the container
+
+Ephemeral containers have no service account token. Borrow the target's, or supply your own. See
+[`kubectl`](tools/kubernetes.md#kubectl).
+
+### `iptables -L` is empty on a node that obviously has Services
+
+You are looking through the wrong back end. Try `iptables-legacy` and `nft list ruleset`. See
+[`iptables`](tools/packets-firewall.md#iptables).
+
+### `bpftrace` or `dmesg` fails with permission errors
+
+They need a privileged container. Use `--profile=sysadmin`, on a node session if possible. Hardened or managed
+platforms may forbid that entirely.
+
+### `iotop` prints `task_delayacct is 0`
+
+The kernel is not collecting per-task I/O delay accounting. Use `pidstat -d` instead, or enable
+`kernel.task_delayacct` on the node.
+
+### Usernames in `ps` or `ls -l` look wrong
+
+They are translated with **this image's** `/etc/passwd`. Use numeric IDs (`ps -eo pid,uid,comm`).
+
+### `top`, `free` and `/proc/meminfo` show far more memory than my limit
+
+They show the node's. Read the cgroup files. See [the throttling recipe](recipes.md#the-pod-is-slow-or-being-throttled).
+
+## Cleanup
+
+- **Ephemeral containers stay in the pod spec.** They disappear when the pod is replaced (a rollout, a
+ reschedule). You cannot remove one by hand.
+- **Copies from `--copy-to`** are ordinary pods: `kubectl delete pod -debug`.
+- **Node debug pods** are ordinary pods named `node-debugger--`: delete them when finished.
+- **Standalone debug pods** (`kubectl run`): use `--rm`, or delete them.
+
+## Still stuck?
+
+Search or open an issue at [github.com/ngpayyappilly/k8s-debug/issues](https://github.com/ngpayyappilly/k8s-debug/issues).
+Include the `kubectl version`, the exact command, the profile you used, and the error text.
diff --git a/mkdocs.yml b/mkdocs.yml
new file mode 100644
index 0000000..4cc97f1
--- /dev/null
+++ b/mkdocs.yml
@@ -0,0 +1,71 @@
+site_name: k8s-debug
+site_description: An ephemeral container image with the tools you need to debug Kubernetes pods and nodes live, and documentation for every utility in it.
+site_url: https://ngpayyappilly.github.io/k8s-debug/
+repo_url: https://github.com/ngpayyappilly/k8s-debug
+repo_name: ngpayyappilly/k8s-debug
+edit_uri: edit/main/docs/
+strict: true
+
+exclude_docs: |
+ requirements.txt
+
+validation:
+ omitted_files: warn
+ absolute_links: warn
+ unrecognized_links: warn
+ anchors: warn
+
+theme:
+ name: material
+ features:
+ - navigation.sections
+ - navigation.top
+ - navigation.instant
+ - search.suggest
+ - search.highlight
+ - content.code.copy
+ - content.action.edit
+ - toc.follow
+ palette:
+ - media: "(prefers-color-scheme: light)"
+ scheme: default
+ primary: indigo
+ toggle:
+ icon: material/weather-night
+ name: Switch to dark mode
+ - media: "(prefers-color-scheme: dark)"
+ scheme: slate
+ primary: indigo
+ toggle:
+ icon: material/weather-sunny
+ name: Switch to light mode
+
+markdown_extensions:
+ - admonition
+ - attr_list
+ - tables
+ - toc:
+ permalink: true
+ - pymdownx.details
+ - pymdownx.inlinehilite
+ - pymdownx.superfences
+ - pymdownx.tabbed:
+ alternate_style: true
+
+nav:
+ - Home: index.md
+ - Getting started:
+ - Installation: getting-started/installation.md
+ - Permissions and profiles: getting-started/permissions.md
+ - Tools:
+ - Overview: tools/index.md
+ - HTTP and connectivity: tools/connectivity.md
+ - DNS: tools/dns.md
+ - Network stack: tools/network-stack.md
+ - Packet capture and firewall: tools/packets-firewall.md
+ - Processes and system: tools/processes.md
+ - Kubernetes and data: tools/kubernetes.md
+ - Shell and files: tools/shell.md
+ - Recipes: recipes.md
+ - Troubleshooting: troubleshooting.md
+ - Contributing: contributing.md
diff --git a/motd.txt b/motd.txt
index 0cc0bbb..ef8ae44 100644
--- a/motd.txt
+++ b/motd.txt
@@ -11,5 +11,5 @@
cat /proc//environ | tr '\0' '\n'
strace -fp needs SYS_PTRACE (--profile=general)
Pod network namespace is always shared: ss -tulpn, tcpdump -i any
- tcpdump needs NET_RAW/NET_ADMIN (--profile=netadmin)
+ tcpdump works by default; iptables/conntrack need NET_ADMIN (--profile=netadmin)
------------------------------------------------------------------
diff --git a/scripts/check-docs.sh b/scripts/check-docs.sh
new file mode 100755
index 0000000..24d8b84
--- /dev/null
+++ b/scripts/check-docs.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+# Fail if a tool the image ships (the TOOLS list in smoke-test.sh) has no
+# documentation section. A tool is documented when some page under docs/tools/
+# has a heading of the form: ## `toolname`
+set -euo pipefail
+
+cd "$(dirname "$0")/.."
+
+# Extract the TOOLS=( ... ) array from the smoke test.
+tools=$(awk '/^TOOLS=\(/{f=1; next} f && /^\)/{exit} f' scripts/smoke-test.sh | sed 's/#.*//')
+
+missing=0
+for t in $tools; do
+ if ! grep -rqE "^##+ \`${t}\`" docs/tools/; then
+ echo "undocumented tool: ${t} (add a '## \`${t}\`' section under docs/tools/)"
+ missing=1
+ fi
+done
+
+if [ "$missing" -ne 0 ]; then
+ exit 1
+fi
+echo "docs cover all $(wc -w <<<"$tools" | tr -d ' ') tools"
diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.sh
index 71b9fe4..92a51f8 100755
--- a/scripts/smoke-test.sh
+++ b/scripts/smoke-test.sh
@@ -6,10 +6,21 @@ set -euo pipefail
IMAGE="${1:-k8s-debug:dev}"
TOOLS=(
- curl wget dig nslookup drill ping traceroute mtr tcpdump nmap ncat nc socat
- ss ip iptables nft conntrack ethtool iperf3 openssl
- strace ltrace gdb lsof htop pidstat iostat iotop bpftrace ps
- jq yq kubectl stern grpcurl git ssh python3 vi nano
+ # HTTP and connectivity
+ curl wget nc ncat socat openssl iperf3 ping tracepath traceroute mtr nmap
+ # DNS
+ dig nslookup drill
+ # network stack
+ ip ss arping ethtool ifconfig netstat brctl
+ # packet capture and firewall
+ tcpdump iptables nft ipset conntrack
+ # processes and system
+ ps pgrep top free vmstat htop lsof fuser pstree pidstat iostat mpstat iotop
+ strace ltrace gdb bpftrace nsenter lsns findmnt dmesg lsmod lspci
+ # kubernetes and data
+ kubectl stern grpcurl yq jq
+ # shell and files
+ bash vi nano less file tree unzip xz git ssh gpg python3
)
fail=0