Skip to content

Instantly share code, notes, and snippets.

@snarlysodboxer
Created January 19, 2023 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snarlysodboxer/e66cd12d5f3a1e06f61661a06621455c to your computer and use it in GitHub Desktop.
Save snarlysodboxer/e66cd12d5f3a1e06f61661a06621455c to your computer and use it in GitHub Desktop.
use stern across contexts
#!/usr/bin/env bash
set -o pipefail -o errexit
# use like:
# ./stern-all-contexts.sh <pod-name>
# or:
# EXCLUDE_CONTEXTS='docker-desktop|other-context' ./stern-all-contexts.sh <pod-name>
EXCLUDE_CONTEXTS=${EXCLUDE_CONTEXTS:-docker-desktop}
trap 'kill $(jobs -p)' EXIT
if ! echo "${@}" | grep -q "\-\-tail"; then
set -- '--tail=1' "$@"
fi
for CONTEXT in $(kubectl config get-contexts -o name); do
if [[ "${CONTEXT}" =~ ^${EXCLUDE_CONTEXTS}$ ]]; then
continue
fi
stern --context="${CONTEXT}" "${@}" &
done
for PID in $(jobs -p); do
wait ${PID}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment