Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print pod name in kubectl logs when using label selector #44812

Closed
nvartolomei opened this issue Apr 23, 2017 · 18 comments
Closed

Print pod name in kubectl logs when using label selector #44812

nvartolomei opened this issue Apr 23, 2017 · 18 comments
Labels
area/kubectl kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@nvartolomei
Copy link
Contributor

Add kubectl logs flag to include pod name on each line in log output. Similar to docker-compose logs. Ideally behind a flag.

@0xmichalis
Copy link
Contributor

@kubernetes/sig-cli-feature-requests @kubernetes/sig-api-machinery-misc

@0xmichalis 0xmichalis added area/kubectl sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. kind/enhancement labels Apr 23, 2017
@smarterclayton
Copy link
Contributor

Is there a capsule design for label selected pods for logs?

@adohe-zz
Copy link

imho, no such capsule design, should we add one for this? @smarterclayton

@nvartolomei
Copy link
Contributor Author

What does "capsule design" mean?

@timothysc
Copy link
Member

timothysc commented May 3, 2017

Just wondering why we couldn't do something very general like pass a formatting modifier string as a flag to other CLI command. Similar to server side queries but more general.

xref: http://research.cs.wisc.edu/htcondor/manual/current/condor_status.html see -format

@mbohlool mbohlool removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 2, 2017
@mbohlool
Copy link
Contributor

mbohlool commented Oct 2, 2017

This does seem like a feature request for kubectl. If it needs a feature from server, please file a separate issue.

@smarterclayton
Copy link
Contributor

smarterclayton commented Oct 3, 2017

The API server would potentially need to support multiple streams of logs coming back from a pod, depending on the implementation. Which is why I asked what the design would be.

@smarterclayton smarterclayton added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 3, 2017
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 7, 2018
@Nowaker
Copy link

Nowaker commented Jan 31, 2018

This would be really helpful. A flag like --pod-names would play well with existing option --timestamps. CC @kubernetes/sig-cli-feature-requests

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 31, 2018
@k8s-ci-robot
Copy link
Contributor

@Nowaker: Reiterating the mentions to trigger a notification:
@kubernetes/sig-cli-feature-requests

In response to this:

This would be really helpful. A flag like --pod-names would play well with existing option --timestamps. CC @kubernetes/sig-cli-feature-requests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 2, 2018
@Nowaker
Copy link

Nowaker commented Mar 2, 2018

Could someone from @kubernetes/sig-cli-feature-requests take a look at this and comment, please? Thanks!

@k8s-ci-robot
Copy link
Contributor

@Nowaker: Reiterating the mentions to trigger a notification:
@kubernetes/sig-cli-feature-requests

In response to this:

Could someone from @kubernetes/sig-cli-feature-requests take a look at this and comment, please? Thanks!

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@soltysh
Copy link
Contributor

soltysh commented Mar 7, 2018

/lifecycle rotten
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Mar 7, 2018
@soltysh
Copy link
Contributor

soltysh commented Mar 7, 2018

/remove-lifecycle rotten
/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Mar 7, 2018
@captain-kark
Copy link

captain-kark commented May 12, 2020

Update: I'm trying out https://github.com/wercker/stern instead.


Hopefully this helps someone, I've only tested it very briefly on darwin/BSD.

function kublogs {
  __label_args=${@:1:2}
  __logs_args=${@:3}
  kubectl get po $__label_args -o name | cut -d / -f 2 | xargs -I{} bash -c 'sed -E "s/([0-9]{5})([0-9]+)?Z/\1Z $1/" <(kubectl logs $1 --timestamps ${@:2})' echo {} $__logs_args
}
kublogs -l app=my-deployment --since 1h -c some-container

It will print the timestamp first, but will be run against each pod individually. Pipe through sort to merge all pod logs together in the order they happened in the cluster.

@Nowaker
Copy link

Nowaker commented May 12, 2020

Can't live without https://github.com/johanhaleby/kubetail. Simple syntax, colored output (different color per pod).

@muvster
Copy link

muvster commented Oct 9, 2020

Now available in the form of --prefix: #76471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
None yet
Development

No branches or pull requests