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

前端 未结 14 1465
不思量自难忘°
不思量自难忘° 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:52

    You can get the logs from multiple containers using labels as Adrian Ng suggested:

    kubectl logs --selector app=yourappname
    

    In case you have a pod with multiple containers, the above command is going to fail and you'll need to specify the container name:

    kubectl logs --selector app=yourappname --container yourcontainername
    

    Note: If you want to see which labels are available to you, the following command will list them all:

    kubectl get pod  -o template --template='{{.metadata.labels}}'
    

    ...where the output will look something like

    map[app:yourappname controller-revision-hash:598302898 pod-template-generation:1]

    Note that some of the labels may not be shared by other pods - picking "app" seems like the easiest one

提交回复
热议问题