1

I was looking for a way to stream the logs of all pods of a specific deployment of mine.
So, some days ago I've found this SO answer giving me a magical command:

kubectl logs -f deployment/<my-deployment> --all-containers=true

However, I've just discovered, after a lot of time debugging, that this command actually shows the logs of just one pod, and not all of the deployment. So I went to Kubectl's official documentation and found nothing relevant on the topic, just the following phrase above the example that uses the deployment, as a kind of selector, for log streaming:

  ...
  
  # Show logs from a kubelet with an expired serving certificate
  kubectl logs --insecure-skip-tls-verify-backend nginx
  
  # Return snapshot logs from first container of a job named hello
  kubectl logs job/hello
  
  # Return snapshot logs from container nginx-1 of a deployment named nginx
  kubectl logs deployment/nginx -c nginx-1

So why is that the first example shown says "Show logs" and the other two say "Return snapshot logs"?

Is it because of this "snapshot" that I can't retrieve logs from all the pods of the deployment? I've searched a lot for more deep documentation on streaming logs with kubectl but couldn't find any.

Teodoro
  • 1,194
  • 8
  • 22

1 Answers1

2

To return all pod(s) log of a deployment you can use the same selector as the deployment. You can retrieve the deployment selector like this kubectl get deployment <name> -o jsonpath='{.spec.selector}' --namespace <name>, then you retrieve logs using the same selector kubectl logs --selector <key1=value1,key2=value2> --namespace <name>

gohm'c
  • 13,492
  • 1
  • 9
  • 16
  • Although your answer is useful, it doesn't answer my original question. But thank you! – Teodoro Dec 27 '21 at 20:04
  • `Is it because of this "snapshot" that I can't retrieve logs from all the pods of the deployment?` - no, as the answer demonstrates to you how you can you do that. – gohm'c Dec 28 '21 at 00:52