Skip to content

Instantly share code, notes, and snippets.

@borsna
Last active October 9, 2023 17:51
Show Gist options
  • Save borsna/c217d9ee6c835128e057acb034f827fe to your computer and use it in GitHub Desktop.
Save borsna/c217d9ee6c835128e057acb034f827fe to your computer and use it in GitHub Desktop.
Tail log for kubernetes pod by geting list of pods and filter by substring
#!/bin/bash
namespace=mynamespace
pods=$(kubectl get po -n $namespace -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{end}')
for i in $(echo $pods | sed "s/\t/ /g")
do
case $i in *"$1"*)
kubectl logs -n $namespace $i --follow;;
esac
done
@borsna
Copy link
Author

borsna commented Oct 9, 2023

Got bored of listing kubernetes pods and then geting the generated name to get a tail log.
call script by:
sh kubectl-log-tail.sh some-service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment