Kubernetes: tail logs from pods with stern
• 178 words • 1 min • updated
You can always use kubectl logs -n {namespace} {pod} [-c {container}] -f to
inspect logs from a specific pod1.
Nonetheless that doesn’t scale when you don’t know which pod you want in the first place.
You could start with deployments, dive into replica sets, and then into individual pods, one by one, but… that is tedious and slow.
We can do better with stern:
⎈ Multi pod and container log tailing for Kubernetes
Usage:
stern pod-query [flags]The pod-query is a regular expression or a Kubernetes resource in the form
<resource>/<name>.
Example:
% stern -n argocd argocdWe can also grep for specific strings in log lines with --include:
% stern -n argocd argocd --include level=errorOr grep -v with --exclude.
It’s better to use --include / --exclude than to | grep, because it
preserves color attributes (each pod has a different color in the aggregated
log output).
The logs stream by default (like tail -f, or kubectl logs -f).
-
-cto specify a container within it, and-fto stream logs à latail -f. ↩︎