@gtadi/k8s-node-debugger 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,183 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or as an addendum to
115
+ the NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the
121
+ Contribution, either alone or combined with the Work.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Liability While Redistributing. While
159
+ redistributing the Work or Derivative Works thereof, You may
160
+ choose to offer, and charge a fee for, acceptance of support,
161
+ warranty, indemnity, or other liability obligations and/or rights
162
+ consistent with this License. However, in accepting such obligations,
163
+ You may act only on Your own behalf and on Your sole responsibility,
164
+ not on behalf of any other Contributor, and only if You agree to
165
+ indemnify, defend, and hold each Contributor harmless for any
166
+ liability incurred by, or claims asserted against, such Contributor
167
+ by reason of your accepting any such warranty or additional liability.
168
+
169
+ END OF TERMS AND CONDITIONS
170
+
171
+ Copyright 2026 Goutam Tadi
172
+
173
+ Licensed under the Apache License, Version 2.0 (the "License");
174
+ you may not use this file except in compliance with the License.
175
+ You may obtain a copy of the License at
176
+
177
+ http://www.apache.org/licenses/LICENSE-2.0
178
+
179
+ Unless required by applicable law or agreed to in writing, software
180
+ distributed under the License is distributed on an "AS IS" BASIS,
181
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
182
+ See the License for the specific language governing permissions and
183
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # k8s node debugger
2
+
3
+ Spin up a privileged debug pod on any Kubernetes node and inspect its full network stack from a browser — no SSH required.
4
+
5
+ One command creates the pod, opens the browser, and cleans up when you're done.
6
+
7
+ ```bash
8
+ node bin/k8s-node-debugger.js <node-name>
9
+ ```
10
+
11
+ ## Screenshots
12
+
13
+ ### Firewall — iptables, nftables, and IPVS tabs
14
+
15
+ ![Firewall view](docs/screenshot-firewall.png)
16
+
17
+ ### Conntrack — live connection tracking
18
+
19
+ ![Conntrack view](docs/screenshot-conntrack-tabs.png)
20
+
21
+ ### Node Health — CPU, memory, disk, PSI, OOM, kubelet logs
22
+
23
+ ![Node Health view](docs/screenshot-health.png)
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ git clone git@github.com:goutamtadi1/k8s-node-debugger.git
29
+ cd k8s-node-debugger
30
+ npm install
31
+ ```
32
+
33
+ Requires `kubectl` on your PATH with an active kubeconfig. The debug image (`nicolaka/netshoot`) is pulled from Docker Hub on first use.
34
+
35
+ ## Usage
36
+
37
+ ```bash
38
+ # list nodes in the current context
39
+ node bin/k8s-node-debugger.js --list
40
+
41
+ # debug a specific node (opens http://localhost:7878)
42
+ node bin/k8s-node-debugger.js <node-name>
43
+
44
+ # options
45
+ node bin/k8s-node-debugger.js <node-name> \
46
+ --namespace kube-system \ # namespace for the debug pod (default: default)
47
+ --context my-ctx \ # kubeconfig context (default: current)
48
+ --port 9000 \ # UI port (default: 7878)
49
+ --keep \ # leave the pod running after exit
50
+ --no-open # don't auto-open the browser
51
+ ```
52
+
53
+ Press **Ctrl-C** to stop the server and delete the debug pod.
54
+
55
+ ## What it shows
56
+
57
+ | Section | Probes |
58
+ |---|---|
59
+ | **Firewall** | iptables (all tables), iptables nat, nftables, IPVS — each as a tab |
60
+ | **DNS** | resolv.conf, nsswitch.conf, /etc/hosts |
61
+ | **Conntrack** | connection table, per-CPU stats, count/max gauge — each as a tab |
62
+ | **Routing** | IPv4 routes, IPv6 routes, policy rules |
63
+ | **Interfaces** | ip addr, ip link stats, ARP/neighbors |
64
+ | **Sockets** | listening sockets, all TCP/UDP with process names |
65
+ | **Kernel** | key net.* sysctls |
66
+ | **Health** | CPU & load, memory, disk usage, PSI pressure, OOM kills, kubelet logs — each as a tab |
67
+ | **GPU** | nvidia-smi status, GPU processes, DCGM health check |
68
+ | **Terminal** | streaming terminal — run any command inside the pod (tcpdump, dig, ping, conntrack -E …) |
69
+
70
+ ### Node Health view features
71
+
72
+ - **CPU & load** — load averages (1/5/15 min) vs core count, CPU model, steal %, top processes
73
+ - **Memory** — used/available/cached/swap gauges from `/proc/meminfo`
74
+ - **Disk usage** — `df -h` per filesystem with usage bars
75
+ - **PSI pressure** — CPU, memory, and I/O stall metrics from `/proc/pressure/*`; colour-coded ok/warn/critical
76
+ - **OOM kills** — parsed dmesg entries with process names and timestamps; empty means no OOM events since boot
77
+ - **kubelet logs** — last 100 lines from journalctl, errors and warnings highlighted
78
+
79
+ ### iptables view features
80
+
81
+ - Tabs per table (mangle · security · raw · filter · nat) with rule counts
82
+ - Collapsible chain cards with default-policy badge and packet/byte counters
83
+ - Colour-coded target badges: ACCEPT / DROP / REJECT / MASQUERADE / DNAT / LOG / MARK / k8s chain / …
84
+ - Human-readable rule summaries with port service names (SSH, HTTPS, etcd, kubelet, k8s-API, NodePort range …)
85
+ - Live search across all tables and chains
86
+ - KUBE-SVC-\* / KUBE-SEP-\* chains collapsed by default; toggle with **K8s chains** button
87
+ - Click any rule to reveal the raw `iptables-save` line
88
+ - **Raw** toggle to fall back to plain text
89
+
90
+ ### conntrack view features
91
+
92
+ - Stat cards: Total · TCP ESTABLISHED · TCP TIME\_WAIT · UDP · ICMP · total bytes
93
+ - Protocol distribution bar and TCP state breakdown bar
94
+ - Top 8 source IPs and top 8 destination ports (with service names)
95
+ - Filter by protocol and TCP state; full-text search by IP, port, or state
96
+ - Connection rows show state badge, ASSURED/UNREPLIED flag, src:port → dst:port, TTL, bytes, and a NAT tag when the reply source differs from the original destination
97
+ - Paginated 200 at a time
98
+ - Per-CPU stats table with drops/errors highlighted in red
99
+ - Count/max capacity gauge (green → amber → red at 50% / 80%)
100
+
101
+ ## How it works
102
+
103
+ The debug pod (`nicolaka/netshoot`) is created with:
104
+
105
+ - `hostNetwork: true` — shares the node's network namespace
106
+ - `hostPID: true` — allows `nsenter` to enter the host mount namespace
107
+ - `privileged: true` — required for iptables / conntrack / tcpdump
108
+ - Host root mounted at `/host` — for reading node files
109
+ - Tolerations for all taints — schedules onto control-plane nodes too
110
+
111
+ The server shells out to your local `kubectl`, so your active kubeconfig, current context, and any exec auth plugins (EKS, GKE, AKS) are reused automatically.
112
+
113
+ ## Environment variables
114
+
115
+ | Variable | Default | Description |
116
+ |---|---|---|
117
+ | `KUBECTL_BIN` | `kubectl` | Path to the kubectl binary |
118
+ | `DEBUGGER_IMAGE` | `nicolaka/netshoot:latest` | Debug container image |
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const k8s = require('../src/k8s');
5
+ const { createServer } = require('../src/server');
6
+
7
+ function parseArgs(argv) {
8
+ const opts = { namespace: 'default', port: 7878, open: true };
9
+ const positional = [];
10
+ for (let i = 0; i < argv.length; i++) {
11
+ const a = argv[i];
12
+ switch (a) {
13
+ case '-n':
14
+ case '--namespace':
15
+ opts.namespace = argv[++i];
16
+ break;
17
+ case '--context':
18
+ opts.context = argv[++i];
19
+ break;
20
+ case '--kubeconfig':
21
+ opts.kubeconfig = argv[++i];
22
+ break;
23
+ case '-p':
24
+ case '--port':
25
+ opts.port = parseInt(argv[++i], 10);
26
+ break;
27
+ case '--no-open':
28
+ opts.open = false;
29
+ break;
30
+ case '--keep':
31
+ opts.keep = true;
32
+ break;
33
+ case '-h':
34
+ case '--help':
35
+ opts.help = true;
36
+ break;
37
+ default:
38
+ positional.push(a);
39
+ }
40
+ }
41
+ opts.node = positional[0];
42
+ return opts;
43
+ }
44
+
45
+ function usage() {
46
+ console.log(`
47
+ k8s-node-debugger — inspect a node's network stack from your browser.
48
+
49
+ Usage:
50
+ k8s-node-debugger <node-name> [options]
51
+ k8s-node-debugger --list # list nodes and exit
52
+
53
+ Options:
54
+ -n, --namespace <ns> Namespace for the debug pod (default: default)
55
+ --context <ctx> kubeconfig context to use (default: current)
56
+ --kubeconfig <path> Explicit kubeconfig path
57
+ -p, --port <port> UI port (default: 7878)
58
+ --no-open Don't auto-open the browser
59
+ --keep Leave the debug pod running on exit
60
+ -h, --help Show this help
61
+
62
+ The active kubeconfig on your shell is used. A privileged pod
63
+ (${k8s.DEBUG_IMAGE}) is created on the target node with
64
+ hostNetwork/hostPID and the host root mounted at /host.
65
+ `);
66
+ }
67
+
68
+ async function openBrowser(url) {
69
+ try {
70
+ const open = (await import('open')).default;
71
+ await open(url);
72
+ } catch {
73
+ /* optional dependency / headless env — ignore */
74
+ }
75
+ }
76
+
77
+ async function main() {
78
+ const opts = parseArgs(process.argv.slice(2));
79
+
80
+ if (opts.help) return usage();
81
+
82
+ const baseOpts = {
83
+ context: opts.context,
84
+ kubeconfig: opts.kubeconfig,
85
+ namespace: opts.namespace,
86
+ };
87
+
88
+ if (opts.node === '--list' || opts.list) {
89
+ const nodes = await k8s.listNodes(baseOpts);
90
+ console.log(`\nNodes (context: ${(await k8s.currentContext(baseOpts)) || 'n/a'}):\n`);
91
+ for (const n of nodes) {
92
+ console.log(
93
+ ` ${n.ready ? '●' : '○'} ${n.name}` +
94
+ `${n.roles.length ? ` [${n.roles.join(',')}]` : ''}` +
95
+ ` ${n.internalIP || ''} ${n.os || ''}`
96
+ );
97
+ }
98
+ console.log('');
99
+ return;
100
+ }
101
+
102
+ if (!opts.node) {
103
+ usage();
104
+ console.error('error: a node name is required (or use --list).\n');
105
+ process.exit(1);
106
+ }
107
+
108
+ const ctx = (await k8s.currentContext(baseOpts)) || 'current';
109
+ console.log(`\n▶ context: ${ctx}`);
110
+ console.log(`▶ target node: ${opts.node}`);
111
+ console.log(`▶ creating privileged debug pod (${k8s.DEBUG_IMAGE})...`);
112
+
113
+ let session;
114
+ try {
115
+ const { podName, namespace } = await k8s.createDebugPod(opts.node, baseOpts);
116
+ session = {
117
+ node: opts.node,
118
+ podName,
119
+ namespace,
120
+ context: opts.context,
121
+ kubeconfig: opts.kubeconfig,
122
+ };
123
+ console.log(`▶ pod: ${namespace}/${podName} — waiting for Ready...`);
124
+ await k8s.waitForPodReady(podName, baseOpts);
125
+ console.log('▶ pod is Ready.');
126
+ } catch (err) {
127
+ console.error(`\n✖ failed to start debug pod: ${err.message}`);
128
+ if (session && session.podName && !opts.keep) {
129
+ await k8s.deletePod(session.podName, baseOpts);
130
+ }
131
+ process.exit(1);
132
+ }
133
+
134
+ const server = createServer(session);
135
+
136
+ let cleaningUp = false;
137
+ const cleanup = async (code = 0) => {
138
+ if (cleaningUp) return;
139
+ cleaningUp = true;
140
+ server.close();
141
+ if (!opts.keep) {
142
+ console.log(`\n▶ deleting debug pod ${session.namespace}/${session.podName}...`);
143
+ await k8s.deletePod(session.podName, baseOpts);
144
+ console.log('▶ done.');
145
+ } else {
146
+ console.log(
147
+ `\n▶ leaving pod ${session.namespace}/${session.podName} running ` +
148
+ `(remove with: kubectl delete pod ${session.podName} -n ${session.namespace}).`
149
+ );
150
+ }
151
+ process.exit(code);
152
+ };
153
+
154
+ process.on('SIGINT', () => cleanup(0));
155
+ process.on('SIGTERM', () => cleanup(0));
156
+
157
+ server.listen(opts.port, () => {
158
+ const url = `http://localhost:${opts.port}`;
159
+ console.log(`\n✓ UI ready → ${url}`);
160
+ console.log(' (press Ctrl-C to stop and clean up the pod)\n');
161
+ if (opts.open) openBrowser(url);
162
+ });
163
+ }
164
+
165
+ main().catch((err) => {
166
+ console.error(err);
167
+ process.exit(1);
168
+ });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@gtadi/k8s-node-debugger",
3
+ "version": "1.0.0",
4
+ "description": "Spin up a privileged debug pod on a target Kubernetes node and inspect its network stack (iptables, resolv.conf, conntrack, routes, sockets) from a browser UI.",
5
+ "bin": {
6
+ "k8s-node-debugger": "bin/k8s-node-debugger.js"
7
+ },
8
+ "type": "commonjs",
9
+ "main": "src/server.js",
10
+ "scripts": {
11
+ "start": "node bin/k8s-node-debugger.js",
12
+ "test": "node --check bin/k8s-node-debugger.js && node --check src/server.js && node --check src/probes.js && node --check src/k8s.js"
13
+ },
14
+ "files": [
15
+ "bin/",
16
+ "src/",
17
+ "public/"
18
+ ],
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "dependencies": {
23
+ "express": "^4.19.2",
24
+ "open": "^8.4.2",
25
+ "ws": "^8.18.0"
26
+ },
27
+ "license": "Apache-2.0"
28
+ }