- 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?
CodePudding user response:
only one pod seems to be the answer.
- i went here How do I get logs from all pods of a Kubernetes replication controller? and it seems that the command
kubectl logs deployment/name
only shows one pod of N - also when you do execute the
kubectl logs
on a deployment it does say it only print to console that it is for one pod (not all the pods)
CodePudding user response:
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