Universal Kubernetes Debug Container Utility
Project description
kdebug - Universal Kubernetes Debug and File Copy Container Utility
Simple utility for launching ephemeral debug containers in Kubernetes pods with interactive shell access, backup capabilities, and a colorful TUI for pod selection.
Similar to kpf, this is a python wrapper around kubectl debug and kubectl cp.
Features
- ๐ Interactive Shell Access - Launch bash/zsh sessions in debug containers directly to the directory of your choice
- ๐พ Backup Capabilities - Copy files/directories from pods with optional compression
- ๐ Multiple Selection Modes - Direct pod, controller-based, or interactive tui
- ๐ฏ Smart Container Selection - Auto-select containers or choose specific targets
- ๐ Root Access Support - Run debug containers as root when needed
- ๐ฆ Controller Support - Works with Deployments, StatefulSets, and DaemonSets
Demo of the debug TUI
Demo of backups
Installation
brew install jessegoodier/kdebug/kdebug
Or
# Clone the repository
git clone https://github.com/jessegoodier/kdebug.git
cd kdebug
Then make it executable and add to something in your PATH
chmod +x bin/kdebug
ln -s $(pwd)/bin/kdebug ~/.local/bin/kdebug
Shell Completion
kdebug supports tab completion for bash and zsh with dynamic lookups for namespaces, pods, and controller names.
Bash
# Add to ~/.bashrc
source <(kdebug --completions bash)
# Or source the file directly
source /path/to/kdebug/completions/kdebug.bash
Zsh
# Option 1: Source directly (add to ~/.zshrc)
source <(kdebug --completions zsh)
# Option 2: Install to fpath (recommended)
mkdir -p ~/.zsh/completions
kdebug --completions zsh > ~/.zsh/completions/_kdebug
# Add to ~/.zshrc before compinit:
fpath=(~/.zsh/completions $fpath)
autoload -Uz compinit && compinit
Completion Features
kdebug --<TAB>- Complete all optionskdebug -n <TAB>- Complete namespace names from clusterkdebug --pod <TAB>- Complete pod names (respects -n flag)kdebug --controller <TAB>- Complete controller typeskdebug --controller sts --controller-name <TAB>- Complete controller nameskdebug --context <TAB>- Complete context names from kubeconfigkdebug --kubeconfig <TAB>- Complete file paths
Usage
Global Options
kdebug supports kubectl-compatible --context and --kubeconfig flags to target different clusters:
# Use a specific context
kdebug --context minikube -n default --pod my-pod
# Use a different kubeconfig file
kdebug --kubeconfig .kubeconfig -n openclaw
# Combine both options
kdebug --kubeconfig /path/to/config --context staging -n myapp --pod api-0
These options are passed to all kubectl commands, including those used for tab completion.
Interactive Mode (TUI)
When no pod or controller is specified, kdebug launches an interactive menu system:
# Interactive mode - select from all resources in current namespace
kdebug
# Interactive mode with specific namespace
kdebug -n openclaw
TUI Features:
- โฌ๏ธโฌ๏ธ Use arrow keys to navigate
- 1๏ธโฃ-9๏ธโฃ Press numbers for quick selection
- โฉ๏ธ Press Enter to confirm
- โ Press 'q' to quit
The TUI displays all pods in the namespace with:
- Color-coded status indicators (Green=Running, Yellow=Pending, etc.)
- Pod names highlighted for easy identification
- Real-time status information
Direct Pod Selection
# Interactive session with direct pod
kdebug -n kubecost --pod aggregator-0 --container aggregator
# Auto-select first container if not specified
kdebug -n kubecost --pod aggregator-0
# Custom shell command
kdebug -n kubecost --pod aggregator-0 --cmd sh
Controller-Based Selection
# Using StatefulSet (sts)
kdebug -n kubecost --controller sts --controller-name aggregator --container aggregator
# Using Deployment
kdebug -n myapp --controller deployment --controller-name frontend --cmd bash
# Using DaemonSet
kdebug -n logging --controller ds --controller-name fluentd
Supported Controller Types:
deploymentordeploy- Kubernetes Deploymentsstatefulsetorsts- StatefulSetsdaemonsetords- DaemonSets
Advanced Features
Change Directory on Start
# Start shell in specific directory
kdebug -n kubecost --pod aggregator-0 --cd-into /var/configs
Backup Mode
# Backup directory (uncompressed)
kdebug -n kubecost --pod aggregator-0 --backup /var/configs
# Backup with compression
kdebug -n kubecost --pod aggregator-0 --backup /var/configs --compress
# Backups are saved to: ./backups/<namespace>/<timestamp>_<pod-name>
Run as Root
# Launch debug container as root user
kdebug -n myapp --pod frontend-abc123 --as-root
Debug Mode
# Show all kubectl commands being executed
kdebug -n myapp --pod frontend-abc123 --debug
Examples
Example 1: Interactive Pod Selection
$ kdebug -n production
Starting interactive pod selection...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Select Pod in namespace: production
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โถ 1. frontend-abc123 (Running)
2. frontend-def456 (Running)
3. backend-ghi789 (Running)
4. database-0 (Running)
5. worker-jkl012 (Pending)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Use โ/โ arrows or numbers to select, Enter to confirm, q to quit
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Example 2: Quick Debug Session
# Launch debug container and get bash shell
kdebug -n kubecost --controller sts --controller-name aggregator --container aggregator
# Output:
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Starting interactive session in pod aggregator-0
# Container: debugger-xyz
# Command: bash
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Example 3: Backup Configuration Files
# Backup with compression
kdebug -n production --pod api-server-0 --backup /etc/app/config --compress
# Output:
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Creating backup from pod api-server-0
# Path: /etc/app/config
# Mode: Compressed (tar.gz)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ Path exists: /etc/app/config
# โ Backup archive created
# โ Backup saved to: ./backups/production/2024-02-04_10-30-45_api-server-0.tar.gz
Color Scheme
kdebug uses a kubecolor-inspired color scheme:
- ๐ต Blue - Borders and separators
- ๐ข Green - Success messages and running status
- ๐ก Yellow - Warnings and pending status
- ๐ด Red - Errors and failed status
- ๐ฃ Magenta - Namespaces
- ๐ท Cyan - Pod and container names
- โช White/Gray - General text and metadata
Requirements
- Python 3.9+
- kubectl configured with cluster access
- Kubernetes cluster with ephemeral containers support (v1.23+)
How It Works
- Resource Discovery - Queries Kubernetes API for controllers/pods
- Debug Container Launch - Creates ephemeral container with debug image
- Process Sharing - Enables
--share-processesfor full pod access - Interactive Session - Attaches to container with TTY
- Cleanup - Terminates debug container after session ends
Troubleshooting
"Operation not supported on socket" Error
The interactive TUI requires a real terminal (TTY). Ensure you're running kdebug in:
- A standard terminal (not piped or redirected)
- Not through automation tools that don't provide TTY
- With proper terminal emulation support
"Pod Security Policy" Warnings
If you see warnings about runAsNonRoot, the pod has security restrictions. Try:
- Running without
--as-rootflag - Checking pod security policies
- Using a different debug image
Container Won't Start
Check:
- Debug image is accessible from cluster
- Pod has sufficient resources
- Network policies allow image pull
- Use
--debugflag to see kubectl commands
License
MIT
Contributing
Contributions welcome! Please open issues or pull requests.
Made with โค๏ธ and Bob
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kdebug-0.4.1.tar.gz.
File metadata
- Download URL: kdebug-0.4.1.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35a802cb0e395e588dd3a112a294b82e3af693fe96f37d025123d063552fa8d3
|
|
| MD5 |
32b093c73e3da40d88a68b08d624216f
|
|
| BLAKE2b-256 |
c4d75a6b967a2b7990b13ae35226c9754b6deda76c7a9d742508ebc38f7e12b0
|
File details
Details for the file kdebug-0.4.1-py3-none-any.whl.
File metadata
- Download URL: kdebug-0.4.1-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b7e1fe147094d26ff95da65a8d932fd301818545f8b067cea539e459ae0833b
|
|
| MD5 |
43dfda1285adb1181faa8ae5597374b2
|
|
| BLAKE2b-256 |
74d324da474f43da8e92415b3aa60568956739ed39a269307eb041006997a581
|