How to get kubectl logs to output pod name alongside logs?
I'm using the handy kubectl logs -l label=value
command to get log from all my pods matching a label. I want to see which pod outputted what log, but only the log text is displayed. Is there a way to control the log format, or a command argument which will let me do this?
kubernetes kubectl
add a comment |
I'm using the handy kubectl logs -l label=value
command to get log from all my pods matching a label. I want to see which pod outputted what log, but only the log text is displayed. Is there a way to control the log format, or a command argument which will let me do this?
kubernetes kubectl
There's an issue matching what I want to accomplish here github.com/kubernetes/kubernetes/issues/44812 but that issue got closed as a feature request. :-(
– Dhiraj Gupta
Nov 23 '18 at 6:27
you can use fluentbit to stream all the logs to ELK and then slice them based on label , pod name , namsepace name etc
– Ijaz Ahmad Khan
Nov 23 '18 at 10:20
add a comment |
I'm using the handy kubectl logs -l label=value
command to get log from all my pods matching a label. I want to see which pod outputted what log, but only the log text is displayed. Is there a way to control the log format, or a command argument which will let me do this?
kubernetes kubectl
I'm using the handy kubectl logs -l label=value
command to get log from all my pods matching a label. I want to see which pod outputted what log, but only the log text is displayed. Is there a way to control the log format, or a command argument which will let me do this?
kubernetes kubectl
kubernetes kubectl
asked Nov 23 '18 at 6:25
Dhiraj GuptaDhiraj Gupta
2,90422337
2,90422337
There's an issue matching what I want to accomplish here github.com/kubernetes/kubernetes/issues/44812 but that issue got closed as a feature request. :-(
– Dhiraj Gupta
Nov 23 '18 at 6:27
you can use fluentbit to stream all the logs to ELK and then slice them based on label , pod name , namsepace name etc
– Ijaz Ahmad Khan
Nov 23 '18 at 10:20
add a comment |
There's an issue matching what I want to accomplish here github.com/kubernetes/kubernetes/issues/44812 but that issue got closed as a feature request. :-(
– Dhiraj Gupta
Nov 23 '18 at 6:27
you can use fluentbit to stream all the logs to ELK and then slice them based on label , pod name , namsepace name etc
– Ijaz Ahmad Khan
Nov 23 '18 at 10:20
There's an issue matching what I want to accomplish here github.com/kubernetes/kubernetes/issues/44812 but that issue got closed as a feature request. :-(
– Dhiraj Gupta
Nov 23 '18 at 6:27
There's an issue matching what I want to accomplish here github.com/kubernetes/kubernetes/issues/44812 but that issue got closed as a feature request. :-(
– Dhiraj Gupta
Nov 23 '18 at 6:27
you can use fluentbit to stream all the logs to ELK and then slice them based on label , pod name , namsepace name etc
– Ijaz Ahmad Khan
Nov 23 '18 at 10:20
you can use fluentbit to stream all the logs to ELK and then slice them based on label , pod name , namsepace name etc
– Ijaz Ahmad Khan
Nov 23 '18 at 10:20
add a comment |
3 Answers
3
active
oldest
votes
Use the awesome kubetail script
I'll have a look at this, it looks interesting, thanks!
– Dhiraj Gupta
Nov 24 '18 at 2:22
add a comment |
As simple as this:
for pod in $(kubectl get po -l key=value -oname); do echo $pod; kubectl logs $pod; done;
this will fetch the names of the pods by their label, then will one by one print the logs after writing the name of the pod. So, it will look like something like this:
pod1
log
log
log
pod2
log
log
log
...
podn
log
log
log
add a comment |
I use stern to show logs from all pods
https://github.com/wercker/stern.
Neat, I'll try this - it looks like exactly what I was looking for, thanks!
– Dhiraj Gupta
Dec 9 '18 at 5:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441553%2fhow-to-get-kubectl-logs-to-output-pod-name-alongside-logs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the awesome kubetail script
I'll have a look at this, it looks interesting, thanks!
– Dhiraj Gupta
Nov 24 '18 at 2:22
add a comment |
Use the awesome kubetail script
I'll have a look at this, it looks interesting, thanks!
– Dhiraj Gupta
Nov 24 '18 at 2:22
add a comment |
Use the awesome kubetail script
Use the awesome kubetail script
answered Nov 23 '18 at 10:21
Nima HashemiNima Hashemi
563
563
I'll have a look at this, it looks interesting, thanks!
– Dhiraj Gupta
Nov 24 '18 at 2:22
add a comment |
I'll have a look at this, it looks interesting, thanks!
– Dhiraj Gupta
Nov 24 '18 at 2:22
I'll have a look at this, it looks interesting, thanks!
– Dhiraj Gupta
Nov 24 '18 at 2:22
I'll have a look at this, it looks interesting, thanks!
– Dhiraj Gupta
Nov 24 '18 at 2:22
add a comment |
As simple as this:
for pod in $(kubectl get po -l key=value -oname); do echo $pod; kubectl logs $pod; done;
this will fetch the names of the pods by their label, then will one by one print the logs after writing the name of the pod. So, it will look like something like this:
pod1
log
log
log
pod2
log
log
log
...
podn
log
log
log
add a comment |
As simple as this:
for pod in $(kubectl get po -l key=value -oname); do echo $pod; kubectl logs $pod; done;
this will fetch the names of the pods by their label, then will one by one print the logs after writing the name of the pod. So, it will look like something like this:
pod1
log
log
log
pod2
log
log
log
...
podn
log
log
log
add a comment |
As simple as this:
for pod in $(kubectl get po -l key=value -oname); do echo $pod; kubectl logs $pod; done;
this will fetch the names of the pods by their label, then will one by one print the logs after writing the name of the pod. So, it will look like something like this:
pod1
log
log
log
pod2
log
log
log
...
podn
log
log
log
As simple as this:
for pod in $(kubectl get po -l key=value -oname); do echo $pod; kubectl logs $pod; done;
this will fetch the names of the pods by their label, then will one by one print the logs after writing the name of the pod. So, it will look like something like this:
pod1
log
log
log
pod2
log
log
log
...
podn
log
log
log
answered Nov 23 '18 at 11:16
surensuren
1,286515
1,286515
add a comment |
add a comment |
I use stern to show logs from all pods
https://github.com/wercker/stern.
Neat, I'll try this - it looks like exactly what I was looking for, thanks!
– Dhiraj Gupta
Dec 9 '18 at 5:00
add a comment |
I use stern to show logs from all pods
https://github.com/wercker/stern.
Neat, I'll try this - it looks like exactly what I was looking for, thanks!
– Dhiraj Gupta
Dec 9 '18 at 5:00
add a comment |
I use stern to show logs from all pods
https://github.com/wercker/stern.
I use stern to show logs from all pods
https://github.com/wercker/stern.
answered Dec 7 '18 at 3:02
Bal ChuaBal Chua
61215
61215
Neat, I'll try this - it looks like exactly what I was looking for, thanks!
– Dhiraj Gupta
Dec 9 '18 at 5:00
add a comment |
Neat, I'll try this - it looks like exactly what I was looking for, thanks!
– Dhiraj Gupta
Dec 9 '18 at 5:00
Neat, I'll try this - it looks like exactly what I was looking for, thanks!
– Dhiraj Gupta
Dec 9 '18 at 5:00
Neat, I'll try this - it looks like exactly what I was looking for, thanks!
– Dhiraj Gupta
Dec 9 '18 at 5:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441553%2fhow-to-get-kubectl-logs-to-output-pod-name-alongside-logs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There's an issue matching what I want to accomplish here github.com/kubernetes/kubernetes/issues/44812 but that issue got closed as a feature request. :-(
– Dhiraj Gupta
Nov 23 '18 at 6:27
you can use fluentbit to stream all the logs to ELK and then slice them based on label , pod name , namsepace name etc
– Ijaz Ahmad Khan
Nov 23 '18 at 10:20