kdebug 0.4.1__tar.gz → 0.6.0__tar.gz

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.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kdebug
3
- Version: 0.4.1
4
- Summary: Universal Kubernetes Debug Container Utility
3
+ Version: 0.6.0
4
+ Summary: TUI for Kubernetes Debug Containers
5
5
  Project-URL: Homepage, https://github.com/jessegoodier/kdebug
6
6
  Project-URL: Repository, https://github.com/jessegoodier/kdebug
7
7
  Author: Jesse Goodier
@@ -14,6 +14,7 @@ Classifier: Operating System :: MacOS
14
14
  Classifier: Operating System :: POSIX :: Linux
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Requires-Python: >=3.9
17
+ Requires-Dist: rich>=14.0
17
18
  Description-Content-Type: text/markdown
18
19
 
19
20
  # kdebug - Universal Kubernetes Debug and File Copy Container Utility
@@ -22,14 +23,17 @@ Simple utility for launching ephemeral debug containers in Kubernetes pods with
22
23
 
23
24
  Similar to [kpf](https://github.com/jessegoodier/kpf), this is a python wrapper around `kubectl debug` and `kubectl cp`.
24
25
 
26
+ >Notice: the default debug container image is <https://github.com/jessegoodier/toolbox/tree/main/common> and may not be ideal for all users. This is configurable both with an arg and a global config file
27
+
25
28
  ## Features
26
29
 
27
- - 🐚 **Interactive Shell Access** - Launch bash/zsh sessions in debug containers directly to the directory of your choice
28
- - 💾 **Backup Capabilities** - Copy files/directories from pods with optional compression
29
- - 🔍 **Multiple Selection Modes** - Direct pod, controller-based, or interactive tui
30
+ - 🐚 **Interactive Shell Access** - Launch bash/sh sessions in debug containers directly to the directory of your choice
31
+ - 💾 **Backup Capabilities** - Copy files/directories from pods with optional compression and configurable local paths
32
+ - 🔍 **Multiple Selection Modes** - Direct pod, controller-based, or interactive TUI
30
33
  - 🎯 **Smart Container Selection** - Auto-select containers or choose specific targets
31
34
  - 🔐 **Root Access Support** - Run debug containers as root when needed
32
35
  - 📦 **Controller Support** - Works with Deployments, StatefulSets, and DaemonSets
36
+ - ⚙️ **Config File** - Set defaults for debug image, shell command, and backup paths
33
37
 
34
38
  <details open>
35
39
  <summary>Demo of the debug TUI</summary>
@@ -49,64 +53,19 @@ Similar to [kpf](https://github.com/jessegoodier/kpf), this is a python wrapper
49
53
  brew install jessegoodier/kdebug/kdebug
50
54
  ```
51
55
 
52
- Or
53
-
54
- ```bash
55
- # Clone the repository
56
- git clone https://github.com/jessegoodier/kdebug.git
57
- cd kdebug
58
- ```
56
+ ## Usage
59
57
 
60
- Then make it executable and add to something in your PATH
58
+ kdebug uses subcommands for its two modes of operation:
61
59
 
62
60
  ```
63
- chmod +x bin/kdebug
64
- ln -s $(pwd)/bin/kdebug ~/.local/bin/kdebug
65
- ```
66
-
67
- ## Shell Completion
68
-
69
- kdebug supports tab completion for bash and zsh with dynamic lookups for namespaces, pods, and controller names.
70
-
71
- ### Bash
72
-
73
- ```bash
74
- # Add to ~/.bashrc
75
- source <(kdebug --completions bash)
76
-
77
- # Or source the file directly
78
- source /path/to/kdebug/completions/kdebug.bash
61
+ kdebug debug [options] # Interactive debug session (default)
62
+ kdebug backup [options] # Backup files from pod
63
+ kdebug [options] # Same as "kdebug debug" for convenience
79
64
  ```
80
65
 
81
- ### Zsh
82
-
83
- ```bash
84
- # Option 1: Source directly (add to ~/.zshrc)
85
- source <(kdebug --completions zsh)
86
-
87
- # Option 2: Install to fpath (recommended)
88
- mkdir -p ~/.zsh/completions
89
- kdebug --completions zsh > ~/.zsh/completions/_kdebug
90
- # Add to ~/.zshrc before compinit:
91
- fpath=(~/.zsh/completions $fpath)
92
- autoload -Uz compinit && compinit
93
- ```
94
-
95
- ### Completion Features
96
-
97
- - `kdebug --<TAB>` - Complete all options
98
- - `kdebug -n <TAB>` - Complete namespace names from cluster
99
- - `kdebug --pod <TAB>` - Complete pod names (respects -n flag)
100
- - `kdebug --controller <TAB>` - Complete controller types
101
- - `kdebug --controller sts --controller-name <TAB>` - Complete controller names
102
- - `kdebug --context <TAB>` - Complete context names from kubeconfig
103
- - `kdebug --kubeconfig <TAB>` - Complete file paths
104
-
105
- ## Usage
106
-
107
66
  ### Global Options
108
67
 
109
- kdebug supports kubectl-compatible `--context` and `--kubeconfig` flags to target different clusters:
68
+ These shared options work with both subcommands:
110
69
 
111
70
  ```bash
112
71
  # Use a specific context
@@ -119,8 +78,6 @@ kdebug --kubeconfig .kubeconfig -n openclaw
119
78
  kdebug --kubeconfig /path/to/config --context staging -n myapp --pod api-0
120
79
  ```
121
80
 
122
- These options are passed to all kubectl commands, including those used for tab completion.
123
-
124
81
  ### Interactive Mode (TUI)
125
82
 
126
83
  When no pod or controller is specified, kdebug launches an interactive menu system:
@@ -133,41 +90,42 @@ kdebug
133
90
  kdebug -n openclaw
134
91
  ```
135
92
 
136
- **TUI Features:**
137
- - ⬆️⬇️ Use arrow keys to navigate
138
- - 1️⃣-9️⃣ Press numbers for quick selection
139
- - ↩️ Press Enter to confirm
140
- - ❌ Press 'q' to quit
141
-
142
- The TUI displays all pods in the namespace with:
143
- - Color-coded status indicators (Green=Running, Yellow=Pending, etc.)
144
- - Pod names highlighted for easy identification
145
- - Real-time status information
93
+ ### Debug Subcommand
146
94
 
147
- ### Direct Pod Selection
95
+ The `debug` subcommand (or naked `kdebug`) launches an interactive shell session in an ephemeral debug container.
148
96
 
149
97
  ```bash
150
- # Interactive session with direct pod
98
+ # Interactive session with direct pod (bare usage = debug)
151
99
  kdebug -n kubecost --pod aggregator-0 --container aggregator
152
100
 
101
+ # Explicit debug subcommand with custom shell
102
+ kdebug debug -n kubecost --pod aggregator-0 --cmd sh
103
+
153
104
  # Auto-select first container if not specified
154
- kdebug -n kubecost --pod aggregator-0
105
+ kdebug debug -n kubecost --pod aggregator-0
155
106
 
156
- # Custom shell command
157
- kdebug -n kubecost --pod aggregator-0 --cmd sh
107
+ # Change to a directory on start
108
+ kdebug debug -n kubecost --pod aggregator-0 --cd-into /var/configs
158
109
  ```
159
110
 
111
+ **Debug-specific options:**
112
+
113
+ | Option | Description |
114
+ |---|---|
115
+ | `--cmd CMD` | Command to run in debug container (default: `bash`) |
116
+ | `--cd-into DIR` | Change to directory on start (via `/proc/1/root`) |
117
+
160
118
  ### Controller-Based Selection
161
119
 
162
120
  ```bash
163
121
  # Using StatefulSet (sts)
164
- kdebug -n kubecost --controller sts --controller-name aggregator --container aggregator
122
+ kdebug --controller sts/aggregator --container aggregator
165
123
 
166
124
  # Using Deployment
167
- kdebug -n myapp --controller deployment --controller-name frontend --cmd bash
125
+ kdebug -n myapp --controller deploy/frontend --cmd sh
168
126
 
169
127
  # Using DaemonSet
170
- kdebug -n logging --controller ds --controller-name fluentd
128
+ kdebug -n logging --controller ds/fluentd
171
129
  ```
172
130
 
173
131
  **Supported Controller Types:**
@@ -175,41 +133,155 @@ kdebug -n logging --controller ds --controller-name fluentd
175
133
  - `statefulset` or `sts` - StatefulSets
176
134
  - `daemonset` or `ds` - DaemonSets
177
135
 
178
- ### Advanced Features
136
+ ### Backup Subcommand
179
137
 
180
- #### Change Directory on Start
138
+ The `backup` subcommand copies files or directories from a pod to your local machine.
181
139
 
182
140
  ```bash
183
- # Start shell in specific directory
184
- kdebug -n kubecost --pod aggregator-0 --cd-into /var/configs
141
+ # Backup a directory (uncompressed)
142
+ kdebug backup -n kubecost --pod aggregator-0 --container-path /var/configs
143
+
144
+ # Backup with compression
145
+ kdebug backup -n kubecost --pod aggregator-0 --container-path /var/configs --compress
146
+
147
+ # Backup with a custom local path using template variables
148
+ kdebug backup --pod web-0 --container-path /var/data \
149
+ --local-path ./my-backups/{namespace}/{pod}
150
+
151
+ # Backup using controller selection
152
+ kdebug backup --controller deploy/kubecost-local-store \
153
+ --container-path /var/configs/localBucket_v002
185
154
  ```
186
155
 
187
- #### Backup Mode
156
+ **Backup-specific options:**
188
157
 
189
- ```bash
190
- # Backup directory (uncompressed)
191
- kdebug -n kubecost --pod aggregator-0 --backup /var/configs
158
+ | Option | Description |
159
+ |---|---|
160
+ | `--container-path PATH` | **(required)** Path inside the container to back up |
161
+ | `--local-path TEMPLATE` | Local destination (default: `./backups/{namespace}/{date}_{pod}`) |
162
+ | `--compress` | Compress backup as tar.gz |
163
+ | `--tar-exclude PATH` | Exclude a path or pattern from the archive (repeatable) |
192
164
 
193
- # Backup with compression
194
- kdebug -n kubecost --pod aggregator-0 --backup /var/configs --compress
165
+ **Using `--tar-exclude`:**
195
166
 
196
- # Backups are saved to: ./backups/<namespace>/<timestamp>_<pod-name>
167
+ Excludes are matched against paths inside the archive and can be repeated. Provide a name or relative pattern — **do not include the full container path prefix**:
168
+
169
+ ```bash
170
+ # Exclude a single subdirectory by name
171
+ kdebug backup -n kubecost --pod aggregator-0 --container-path /var/configs \
172
+ --compress --tar-exclude waterfowl
173
+
174
+ # Exclude multiple paths
175
+ kdebug backup -n kubecost --pod aggregator-0 --container-path /var/configs \
176
+ --compress --tar-exclude waterfowl --tar-exclude tmp --tar-exclude '*.log'
197
177
  ```
198
178
 
199
- #### Run as Root
179
+ **Template variables for `--local-path`:**
180
+
181
+ | Variable | Value |
182
+ |---|---|
183
+ | `{namespace}` | Kubernetes namespace |
184
+ | `{pod}` | Pod name |
185
+ | `{date}` | Timestamp (`YYYY-MM-DD_HH-MM-SS`) |
186
+ | `{container}` | Target container name |
187
+
188
+ ### Run as Root
200
189
 
201
190
  ```bash
202
191
  # Launch debug container as root user
203
192
  kdebug -n myapp --pod frontend-abc123 --as-root
204
193
  ```
205
194
 
206
- #### Debug Mode
195
+ ### Verbose Mode
207
196
 
208
197
  ```bash
209
198
  # Show all kubectl commands being executed
210
- kdebug -n myapp --pod frontend-abc123 --debug
199
+ kdebug -n myapp --pod frontend-abc123 --verbose
200
+ ```
201
+
202
+ ## Config File
203
+
204
+ kdebug supports a JSON config file at `~/.config/kdebug/kdebug.json` (respects `XDG_CONFIG_HOME`). CLI flags always take priority over config values.
205
+
206
+ ```json
207
+ {
208
+ "debugImage": "busybox:latest",
209
+ "cmd": "sh",
210
+ "cdInto": "/app",
211
+ "backupContainerPath": "/var/data",
212
+ "backupLocalPath": "./backups/{namespace}/{date}_{pod}"
213
+ }
214
+ ```
215
+
216
+ | Key | Description | Default |
217
+ |---|---|---|
218
+ | `debugImage` | Debug container image | `ghcr.io/jessegoodier/toolbox-common:latest` |
219
+ | `cmd` | Shell command for debug sessions | `bash` |
220
+ | `cdInto` | Directory to cd into on start | *(none)* |
221
+ | `backupContainerPath` | Default container path for backups | *(none)* |
222
+ | `backupLocalPath` | Default local path template for backups | `./backups/{namespace}/{date}_{pod}` |
223
+
224
+ String values support `${ENV_VAR}` expansion:
225
+
226
+ ```json
227
+ {
228
+ "debugImage": "${MY_DEBUG_IMAGE}",
229
+ "backupLocalPath": "${HOME}/kdebug-backups/{namespace}/{date}_{pod}"
230
+ }
231
+ ```
232
+
233
+ ### Example: Using busybox as debug image
234
+
235
+ If you don't need the full toolbox image, busybox is a lightweight alternative:
236
+
237
+ ```json
238
+ {
239
+ "debugImage": "busybox:latest",
240
+ "cmd": "sh"
241
+ }
242
+ ```
243
+
244
+ Since busybox doesn't include bash, set `cmd` to `sh`. With this config, simply run `kdebug --pod my-pod` and it will use busybox with sh automatically.
245
+
246
+ ## Shell Completion
247
+
248
+ kdebug supports tab completion for bash and zsh with dynamic lookups for namespaces, pods, controller names, and subcommands.
249
+
250
+ ### Bash
251
+
252
+ ```bash
253
+ # Add to ~/.bashrc
254
+ source <(kdebug --completions bash)
255
+
256
+ # Or source the file directly
257
+ source /path/to/kdebug/completions/kdebug.bash
211
258
  ```
212
259
 
260
+ ### Zsh
261
+
262
+ ```bash
263
+ # Option 1: Source directly (add to ~/.zshrc)
264
+ source <(kdebug --completions zsh)
265
+
266
+ # Option 2: Install to fpath (recommended)
267
+ mkdir -p ~/.zsh/completions
268
+ kdebug --completions zsh > ~/.zsh/completions/_kdebug
269
+ # Add to ~/.zshrc before compinit:
270
+ fpath=(~/.zsh/completions $fpath)
271
+ autoload -Uz compinit && compinit
272
+ ```
273
+
274
+ ### Completion Features
275
+
276
+ - `kdebug <TAB>` - Complete subcommands (`debug`, `backup`)
277
+ - `kdebug --<TAB>` - Complete shared options
278
+ - `kdebug debug --<TAB>` - Complete debug-specific options
279
+ - `kdebug backup --<TAB>` - Complete backup-specific options
280
+ - `kdebug -n <TAB>` - Complete namespace names from cluster
281
+ - `kdebug --pod <TAB>` - Complete pod names (respects -n flag)
282
+ - `kdebug --controller <TAB>` - Complete controller types and names
283
+ - `kdebug --context <TAB>` - Complete context names from kubeconfig
284
+
213
285
  ## Examples
214
286
 
215
287
  ### Example 1: Interactive Pod Selection
@@ -238,7 +310,7 @@ Use ↑/↓ arrows or numbers to select, Enter to confirm, q to quit
238
310
 
239
311
  ```bash
240
312
  # Launch debug container and get bash shell
241
- kdebug -n kubecost --controller sts --controller-name aggregator --container aggregator
313
+ kdebug -n kubecost --controller sts/aggregator --container aggregator
242
314
 
243
315
  # Output:
244
316
  # ══════════════════════════════════════════════════════════════════════
@@ -248,21 +320,25 @@ kdebug -n kubecost --controller sts --controller-name aggregator --container agg
248
320
  # ══════════════════════════════════════════════════════════════════════
249
321
  ```
250
322
 
251
- ### Example 3: Backup Configuration Files
323
+ ### Example 3: Backup with Custom Local Path
252
324
 
253
325
  ```bash
254
- # Backup with compression
255
- kdebug -n production --pod api-server-0 --backup /etc/app/config --compress
326
+ # Backup with compression to a custom path
327
+ kdebug backup -n production --pod api-server-0 \
328
+ --container-path /etc/app/config \
329
+ --local-path ./config-backups/{namespace}/{date}_{pod} \
330
+ --compress
256
331
 
257
332
  # Output:
258
333
  # ══════════════════════════════════════════════════════════════════════
259
334
  # Creating backup from pod api-server-0
260
- # Path: /etc/app/config
335
+ # Container path: /etc/app/config
336
+ # Local path: ./config-backups/production/2024-02-04_10-30-45_api-server-0.tar.gz
261
337
  # Mode: Compressed (tar.gz)
262
338
  # ══════════════════════════════════════════════════════════════════════
263
339
  # ✓ Path exists: /etc/app/config
264
340
  # ✓ Backup archive created
265
- # ✓ Backup saved to: ./backups/production/2024-02-04_10-30-45_api-server-0.tar.gz
341
+ # ✓ Backup saved to: ./config-backups/production/2024-02-04_10-30-45_api-server-0.tar.gz
266
342
  ```
267
343
 
268
344
  ## Color Scheme
@@ -313,7 +389,7 @@ Check:
313
389
  - Debug image is accessible from cluster
314
390
  - Pod has sufficient resources
315
391
  - Network policies allow image pull
316
- - Use `--debug` flag to see kubectl commands
392
+ - Use `--verbose` flag to see kubectl commands
317
393
 
318
394
  ## License
319
395
 
@@ -325,4 +401,4 @@ Contributions welcome! Please open issues or pull requests.
325
401
 
326
402
  ---
327
403
 
328
- Made with ❤️ and Bob
404
+ Made with ❤️ and Bob