Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.