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