0
  • I need to see the logs of all the pods in a deployment with N worker pods
  • When I do kubectl logs deployment/name --tail=0 --follow the command syntax makes me assume that it will tail all pods in the deployment
  • However when I go to process I don't see any output as expected until I manually view the logs for all N pods in the deployment

Does kubectl log deployment/name get all pods or just one pod?

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177

3 Answers3

1

only one pod seems to be the answer.

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
1

Yes, if you run kubectl logs with a deployment, it will return the logs of only one pod from the deployment.

However, you can accomplish what you are trying to achieve by using the -l flag to return the logs of all pods matching a label.

For example, let's say you create a deployment using:

kubectl create deployment my-dep --image=nginx --replicas=3

Each of the pods gets a label app=my-dep, as seen here:

$ kubectl get pods -l app=my-dep
NAME                      READY   STATUS    RESTARTS   AGE
my-dep-6d4ddbf4f7-8jnsw   1/1     Running   0          6m36s
my-dep-6d4ddbf4f7-9jd7g   1/1     Running   0          6m36s
my-dep-6d4ddbf4f7-pqx2w   1/1     Running   0          6m36s

So, if you want to get the combined logs of all pods in this deployment you can use this command:

kubectl logs -l app=my-dep
Brian Pursley
  • 1,098
  • 7
  • 18
0

Kindly run below command in order to get logs for all pods in kubernets by single command at once.

kubectl get pods -n default|grep -v NAME|awk '{print $1}'|while read pods;do kubectl logs $pods;echo;done
linux.cnf
  • 519
  • 6
  • 7