Skip to content

Instantly share code, notes, and snippets.

@aaronzirbes
Created May 18, 2017 17:53
Show Gist options
  • Save aaronzirbes/be0718de434a3d6c18a515c58140d1f5 to your computer and use it in GitHub Desktop.
Save aaronzirbes/be0718de434a3d6c18a515c58140d1f5 to your computer and use it in GitHub Desktop.
Tails multiple k8s pods
#!/bin/bash
default_filter="(event.*|container-container.*|dci-osn-bridge.*)"
filter="${1}"
color=32
if [ "$filter" == "" ]; then
filter="${default_filter}"
fi
function getPods() {
kubectl get pod \
|cut -f 1 -d ' ' \
|grep -v 'NAME' \
|grep -E "${filter}"
}
function tailPod() {
pod="${1}"
kubectl logs -f $pod | sed -e "s/^/${pod}: /" |grep -E "^${pod}"
}
function tailEm() {
pods="${1}"
for pod in $pods; do
echo "tailing ${pod}"
tailPod $pod &
done
}
function waitForEm() {
for job in `jobs -p`; do
wait $job || let "FAIL+=1"
done
}
podlist=`getPods filter`
echo "pods: ${podlist}"
tailEm "$podlist"
waitForEm
pkill kubectl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment