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
Another solution that I would consider is using K9S which is a great kube administration tool.
After installation, the usage is very straightforward:
k9s -n my-namespace --context the_context_name_in_kubeconfig
(If kubeconfig is not in the default location add KUBECONFIG=path/to/kubeconfig
prefix).
The default view will list all pods as a list:
We can change the view to other Kube controllers like replica set (question asked for replication controllers so notice they are deprecated), deployments, cron jobs, etc' by entering a colon :
and start typing the desired controller - as we can see K9S provides autocompletion for us:
And we can see all replica sets in the current namespace:
We can just choose the desired replica set by clicking enter and then we'll see the list of all pods which are related to this replica set - we can then press on 'l' to view logs of each pod.
So, unlike in the case of stern, we still need to go on each pod and view its logs but I think it is very convenient with K9S - we first view all pods of a related controller and then investigate logs of each pod by simply navigating with enter
, l
and escape
.
In this example, you can replace the <namespace>
and <app-name>
to get the logs when there are multiple Containers defined in a Pod.
kubectl -n <namespace> logs -f deployment/<app-name>
--all-containers=true --since=10m