kubectl
kubectl copied to clipboard
Make `kubectl log deployment/foo` read logs from **all** pods
What would you like to be added:
Up to now, kubectl log deployment/foo
outputs the logs of one pod:
❯ kubectl logs deployments/foo --follow >> foo.log
Found 2 pods, using pod/foo-647ffff4b6-k9c5c
It would be very handy if kubectl
could output the logs of all pods of the deployment.
Why is this needed:
The workaround is to use label selectors:
kubectl logs -l app=myapp
But that's not easily automated.
Imagine you get the name and the namespace of a deployment in a script.
There is no easy and automated way to get the matching label selector.
It would be great if kubectl
could support reading the logs from all pods of a deployment.
Related thread on slack: https://kubernetes.slack.com/archives/C2GL57FJ4/p1700558613585049?thread_ts=1700558613.585049&cid=C2GL57FJ4
/assign
@ankritisachan is the best person to work on this feature, thanks for taking this!
kubectl logs --help
is your friend, you'll find there:
...
Options:
--all-containers=false:
Get all containers' logs in the pod(s).
...
That flag should do what you're looking for.
Misread the bit about --all-pods
. I had a short conversation about this topic on slack, we'll try to cover this one next week during SIG-CLI bug scrub.
/triage accepted
I needed this feature a couple of times and support the implementation. (But we probably shouldn't change the default behavior and manage this via new flag, WDYT?)
What would the behavior be while the kubectl logs
command is running, and new pods spin up (or go away)? Would these be noted explicitly? Would that match the user expectation?
Third-party tools like https://github.com/stern/stern or https://github.com/boz/kail support this scenario to some extent.
@ahmetb good question. I would like to see the logs of the new pods, too.
Maybe have the source pod name appended to the log line so it's obvious when pods come and go.
/assign
@cmwylie19 has a PR ready to ship soon for this.
@cmwylie19 has a PR ready to ship soon for this.
/assign
@ahmetb to answer your question I think that functionality should be coupled to --follow
instead of us adding a --all-pods
here. Should be a separate issue if we decide to change the functionality for new pods/replicas/etc.
Thoughts?
WIP - https://github.com/kubernetes/kubernetes/pull/123874