Created
January 19, 2023 18:48
-
-
Save snarlysodboxer/e66cd12d5f3a1e06f61661a06621455c to your computer and use it in GitHub Desktop.
use stern across contexts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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