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

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

    I use this simple script to get a log from the pods of a deployment:

    #!/usr/bin/env bash
    
    DEPLOYMENT=$1
    
    for p in $(kubectl get pods | grep ^${DEPLOYMENT}- | cut -f 1 -d ' '); do 
        echo --------------------------- 
        echo $p 
        echo --------------------------- 
        kubectl logs $p
    done
    

    Gist of the script

    Usage: log_deployment.sh "deployment-name".

    Script will then show log of all pods that start with that "deployment-name".

提交回复
热议问题