How do I get logs from all pods of a Kubernetes replication controller?

前端 未结 14 1332
不思量自难忘°
不思量自难忘° 2021-01-29 23:14

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

14条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-29 23:59

    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.

提交回复
热议问题