26 lines
615 B
Bash
Executable File

#!/bin/bash
NS="$1"
PODS="`mktemp`"
kubectl -n "$NS" --output=json get pods \
| jq -r .items[].metadata.name \
> "$PODS"
for POD in $(cat "$PODS"); do
CONTAINERS="`mktemp`"
kubectl -n "$NS" --output=json get pod "$POD" \
| jq -r .spec.containers[].name \
> "$CONTAINERS"
for CONTAINER in $(cat "$CONTAINERS"); do
# echo -e "$POD:\t$CONTAINER"
if [ "$CONTAINER" = "$2" ]; then
if [ "$3" = "-f" ]; then
kubectl -n "$NS" logs -f "$POD" -c "$CONTAINER"
else
kubectl -n "$NS" logs "$POD" -c "$CONTAINER"
fi
fi
done
rm "$CONTAINERS"
done
rm "$PODS"