Running kubectl logs
shows me the stderr/stdout of one Kubernetes container.
How can I get the aggregated stderr/stdout of a set of pods, preferably those
If the pods are named meaningfully one could use simple Plain Old Bash:
keyword=nodejs
command="cat <("
for line in $(kubectl get pods | \
grep $keyword | grep Running | awk '{print $1}'); do
command="$command (kubectl logs --tail=2 -f $line &) && "
done
command="$command echo)"
eval $command
Explanation: Loop through running pods with name containing "nodejs". Tail the log for each of them in parallel (single ampersand runs in background) ensuring that if any of the pods fail the whole command exits (double ampersand). Cat the streams from each of the tail commands into a unique stream. Eval is needed to run this dynamically built command.