This guide covers using Kubernetes ephemeral containers for live debugging of GistPin pods.
Ephemeral containers allow you to attach debug containers to running pods without modifying the original pod spec. This is invaluable for:
- Debugging production issues without restarting pods
- Inspecting network connectivity and DNS resolution
- Analyzing running processes and resource usage
- Testing connectivity to external services
- Investigating application state and memory
- Kubernetes cluster v1.16+ with ephemeral containers feature enabled
kubectlconfigured with appropriate cluster access- Debug service account (
debug-sa) with proper RBAC - Approved debug container images (see below)
| Image | Use Case |
|---|---|
nicolaka/netshoot:latest |
Network diagnostics (default) |
busybox:latest |
Basic networking, DNS, file operations |
curlimages/curl:latest |
HTTP/API testing |
alpine:latest |
Lightweight general debugging |
python:3.11-slim |
Python application debugging |
node:18-slim |
Node.js application debugging |
Important: Only approved images may be used in production namespaces. The debug-pod.sh script validates images against this list.
# Basic debug session
./infrastructure/scripts/debug-pod.sh -p <pod-name> -n gistpin-prod
# Use a specific image
./infrastructure/scripts/debug-pod.sh -p <pod-name> -i busybox:latest
# Non-interactive mode (logs only)
./infrastructure/scripts/debug-pod.sh -p <pod-name> --non-interactive
# Dry run (show what would happen)
./infrastructure/scripts/debug-pod.sh -p <pod-name> --dry-runkubectl get pods -n gistpin-prod./infrastructure/scripts/debug-pod.sh --list-imagesThe debug role (infrastructure/k8s/rbac/debug-role.yaml) grants the following permissions:
| Resource | Verbs |
|---|---|
| pods | get, list, watch |
| pods/exec | create |
| pods/attach | create |
| pods/portforward | create |
| pods/log | get |
| pods/status | get |
| pods/proxy | create |
| services | get, list |
| endpoints | get, list |
| configmaps | get, list |
| Resource | Verbs |
|---|---|
| namespaces | get, list |
| nodes | get, list |
| pods | get, list, watch |
| events | get, list |
- Name:
debug-sa - Namespace:
gistpin-debug - Bindings: RoleBinding (gistpin namespace) + ClusterRoleBinding (cluster-wide)
Apply the debug RBAC configuration:
kubectl apply -f infrastructure/k8s/rbac/debug-role.yamlThis creates:
gistpin-debugnamespace- Debug configuration and scripts
- Service account with proper RBAC
- Audit logging configuration
# Debug network connectivity from a pod
kubectl debug -it <pod-name> -n gistpin-prod --image=nicolaka/netshoot:latest
# Inside the debug container:
ping backend-service.gistpin-prod.svc.cluster.local
nslookup api.stellar.org
curl -v http://backend-service/health# Attach debug container and inspect processes
kubectl debug -it <pod-name> -n gistpin-prod --image=alpine:latest
# Inside the debug container:
ps aux
top -bn1
cat /proc/1/cmdline# Access file system of running pod
kubectl debug -it <pod-name> -n gistpin-prod --image=alpine:latest
# Inside the debug container:
ls -la /app/
cat /app/config.json
find / -name "*.log" 2>/dev/null# Test database connectivity
kubectl debug -it <pod-name> -n gistpin-prod --image=postgres:15
# Inside the debug container:
psql $DATABASE_URL -c "SELECT 1"All debug sessions are logged to:
/var/log/gistpin/debug-audit.log
Log entries include:
- Timestamp
- Action (create, session start/end, cleanup)
- User performing the action
- Target namespace, pod, and container
- Image used
- Session status
- Timeout configuration
{
"timestamp": "2024-01-15T10:30:00Z",
"action": "debug_session_start",
"user": "developer",
"namespace": "gistpin-prod",
"pod": "backend-abc123",
"container": "debug-1705312200",
"image": "nicolaka/netshoot:latest",
"status": "initiated",
"timeout": "3600"
}- Debug containers run with
SYS_PTRACEcapability for process inspection - Containers run as root (required for some debugging operations)
- Resource limits are enforced (CPU: 200m, Memory: 128Mi)
- Only pre-approved images may be used
- Image validation occurs before container creation
- Custom images require approval via configuration update
- Debug access is restricted to the
debug-saservice account - RBAC limits operations to necessary actions only
- Audit logging tracks all debug activities
- Debug containers persist until pod termination
- Use
--cleanupflag to log cleanup actions - Monitor debug container count in production namespaces
Ensure your cluster supports ephemeral containers (Kubernetes v1.16+). Check with:
kubectl api-resources | grep ephemeralcontainersOnly approved images can be used. Check the list:
./infrastructure/scripts/debug-pod.sh --list-imagesTo add images, update the APPROVED_IMAGES list in:
infrastructure/k8s/rbac/debug-role.yaml(ConfigMap)infrastructure/scripts/debug-pod.sh(script variable)
Ensure the debug RBAC is applied:
kubectl apply -f infrastructure/k8s/rbac/debug-role.yaml
kubectl get clusterrole debug-cluster-role
kubectl get rolebinding debug-rolebinding -n gistpinVerify the pod exists and you have access:
kubectl get pods -n <namespace> | grep <pod-name>- Use the default image (
nicolaka/netshoot:latest) unless you need specific tools - Set appropriate timeouts to prevent orphaned debug containers
- Clean up after debugging sessions
- Review audit logs regularly for security compliance
- Use dry-run mode to verify actions before execution
- Document findings before terminating debug sessions
- Limit debug sessions in production to minimize resource impact