Reputation: 3433
What is the purpose of kubectl logs deploy/my-deployment
shown at https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-deployments-and-services?
I would think it will show me logs from all the pods deployed as part of the my-deployment
object. However, even though I have 2 pods in my deployment, that command shows logs from only one of them.
Upvotes: 5
Views: 5910
Reputation: 295
By following documentation provided, when there are multiple Pods using the below command, it displays logs from only one Pod at a time it will pick randomly one at a point of time.
kubectl get pods -n kube-system | grep coredns
If there are multiple containers then one can specify by using -c
and mention the container name.
By following the Stren documentation, one can get the logs from multiple containers within a pod. Using the below command will display the multiple container data.
kubectl logs deploy/my-deployment -c my-container
Upvotes: 0
Reputation: 116
This should work:
kubectl -n <namespace> logs -l <label_selector> --all-containers=true -f --tail=25
Upvotes: 3
Reputation: 14678
If your deployment has multiple pod replicas, then kubectl logs deployment/...
will just pick one on its own.
Here is an example:
kubectl get pods -n kube-system | grep coredns
coredns-78fcd69978-dqf95 1/1 Running 0 42h
coredns-78fcd69978-vgvf2 1/1 Running 0 42h
kubectl logs deployment/coredns -n kube-system
Found 2 pods, using pod/coredns-78fcd69978-vgvf2
Upvotes: 3
Reputation: 301
As you can see from the documentation you linked:
kubectl logs deploy/my-deployment # dump Pod logs for a Deployment (single-container case)
kubectl logs deploy/my-deployment -c my-container # dump Pod logs for a Deployment (multi-container case)
kubectl logs deploy/my-deployment
is used when you have just one container. So in your case is probably taking the first one. If you have multiple containers you have to specify one with -c
option.
If you want to have logs from multiple pods, you can use Stern
Upvotes: 0