How to get kubectl logs to output pod name alongside logs?












0














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?










share|improve this question






















  • 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
















0














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?










share|improve this question






















  • 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














0












0








0







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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 6:25









Dhiraj Gupta

2,80422337




2,80422337












  • 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










  • 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












3 Answers
3






active

oldest

votes


















1














Use the awesome kubetail script






share|improve this answer





















  • I'll have a look at this, it looks interesting, thanks!
    – Dhiraj Gupta
    Nov 24 '18 at 2:22



















1














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





share|improve this answer





























    1














    I use stern to show logs from all pods
    https://github.com/wercker/stern.






    share|improve this answer





















    • Neat, I'll try this - it looks like exactly what I was looking for, thanks!
      – Dhiraj Gupta
      Dec 9 '18 at 5:00











    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    Use the awesome kubetail script






    share|improve this answer





















    • I'll have a look at this, it looks interesting, thanks!
      – Dhiraj Gupta
      Nov 24 '18 at 2:22
















    1














    Use the awesome kubetail script






    share|improve this answer





















    • I'll have a look at this, it looks interesting, thanks!
      – Dhiraj Gupta
      Nov 24 '18 at 2:22














    1












    1








    1






    Use the awesome kubetail script






    share|improve this answer












    Use the awesome kubetail script







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 10:21









    Nima Hashemi

    463




    463












    • 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




    I'll have a look at this, it looks interesting, thanks!
    – Dhiraj Gupta
    Nov 24 '18 at 2:22













    1














    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





    share|improve this answer


























      1














      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





      share|improve this answer
























        1












        1








        1






        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





        share|improve this answer












        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 11:16









        suren

        1,260515




        1,260515























            1














            I use stern to show logs from all pods
            https://github.com/wercker/stern.






            share|improve this answer





















            • Neat, I'll try this - it looks like exactly what I was looking for, thanks!
              – Dhiraj Gupta
              Dec 9 '18 at 5:00
















            1














            I use stern to show logs from all pods
            https://github.com/wercker/stern.






            share|improve this answer





















            • Neat, I'll try this - it looks like exactly what I was looking for, thanks!
              – Dhiraj Gupta
              Dec 9 '18 at 5:00














            1












            1








            1






            I use stern to show logs from all pods
            https://github.com/wercker/stern.






            share|improve this answer












            I use stern to show logs from all pods
            https://github.com/wercker/stern.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 7 '18 at 3:02









            Bal Chua

            57715




            57715












            • 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




            Neat, I'll try this - it looks like exactly what I was looking for, thanks!
            – Dhiraj Gupta
            Dec 9 '18 at 5:00


















            draft saved

            draft discarded




















































            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo