Skip to content

Instantly share code, notes, and snippets.

@jphalip
Created February 23, 2025 16:56
Show Gist options
  • Save jphalip/68eb9819da31673c11cbec15807cd8ef to your computer and use it in GitHub Desktop.
Save jphalip/68eb9819da31673c11cbec15807cd8ef to your computer and use it in GitHub Desktop.
Access a pod and execute a command
function pod_exec() {
POD_NAME_PATTERN=$1
ARGS="${@:2}"
kubectl exec -it $(kubectl get pods --field-selector=status.phase=Running -o name | grep -m1 $POD_NAME_PATTERN | cut -d'/' -f 2) -- bash -c "$ARGS"
}
function pod_bash() {
pod_exec $1 bash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment