kuberneteskubectl

kubectl logs deploy/my-deployment does not show logs from all pods


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.


Solution

  • 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