Skip to main content

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

debug tui

Demo of backups

backup demo

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 options
  • kdebug -n <TAB> - Complete namespace names from cluster
  • kdebug --pod <TAB> - Complete pod names (respects -n flag)
  • kdebug --controller <TAB> - Complete controller types
  • kdebug --controller sts --controller-name <TAB> - Complete controller names
  • kdebug --context <TAB> - Complete context names from kubeconfig
  • kdebug --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:

  • deployment or deploy - Kubernetes Deployments
  • statefulset or sts - StatefulSets
  • daemonset or ds - 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

  1. Resource Discovery - Queries Kubernetes API for controllers/pods
  2. Debug Container Launch - Creates ephemeral container with debug image
  3. Process Sharing - Enables --share-processes for full pod access
  4. Interactive Session - Attaches to container with TTY
  5. 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-root flag
  • 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 --debug flag to see kubectl commands

License

MIT

Contributing

Contributions welcome! Please open issues or pull requests.


Made with โค๏ธ and Bob

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kdebug-0.4.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kdebug-0.4.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

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

Hashes for kdebug-0.4.1.tar.gz
Algorithm Hash digest
SHA256 35a802cb0e395e588dd3a112a294b82e3af693fe96f37d025123d063552fa8d3
MD5 32b093c73e3da40d88a68b08d624216f
BLAKE2b-256 c4d75a6b967a2b7990b13ae35226c9754b6deda76c7a9d742508ebc38f7e12b0

See more details on using hashes here.

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

Hashes for kdebug-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b7e1fe147094d26ff95da65a8d932fd301818545f8b067cea539e459ae0833b
MD5 43dfda1285adb1181faa8ae5597374b2
BLAKE2b-256 74d324da474f43da8e92415b3aa60568956739ed39a269307eb041006997a581

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page