24 June 2019

Streaming kubernetes logs from multiple replicas

I have been really busy these days with kubernetes. Not only managing it but also developing microservices on top of it. One thing that has been particularly annoying is viewing logs in the command line from multiple replicas. First I installed stern and then I tried kubetail. Both are fine but require me to remember some commands on top of all the commands I have to remember using kubectl. 

I was reading this document the other day and noticed the paragraph:

Begin streaming the logs from all containers in pods defined by label app=nginx
kubectl logs -f -l app=nginx --all-containers=true

I am not sure when this feature was added but I wanted to try it out and see if it was working the way I expected it. So I tried it out on one of the microservices I am working on.
I have a microservice called user-information it is of kind deployment and has the replica count set to 3. I want to stream all pod logs of this service so I tried:

kubectl logs -f --namespace user-information -l app=user-information

and see there all logs from all pods displayed in my console! Nice. No more external tools, just plain kubectl  and grep

Bonus

If your services are structured and all of them have labels (which they should) you can further simplify the above command by adding a function to your ~/.functions file. Open the ~/.functionsfile with your preferred editor and paste the following block inside it:

logs() {
  kubectl logs -f -n $1 -l app=$1 --max-log-requests 5 --all-containers=true --timestamps=true
}

in a new terminal I can then simply view the logs with:

logs user-information

Caveats

Unfortunately, this works only on deployments / statefulSets with replication count <= 5. If you try the above and encounter this

error: you are attempting to follow 6 log streams, but maximum allowed concurrency is 5

You might need to resort to something else then kubectl.

7  question_answer

  • said on 13 March 2020 08:47

    Canine Cephalexin Photos <a href=http://apcialisle.com/#>Buy Cialis</a> Efectos Colaterales Del Viagra <a href=http://apcialisle.com/#>Buy Cialis</a> Buy Generic Plavix Online India

  • said on 14 March 2020 21:58

    Isotretinoin cash delivery overseas <a href=http://apcialisle.com/#>cialis</a> Priligy Preis Apotheke <a href=http://apcialisle.com/#>Cialis</a> Clomid 200g

  • said on 15 March 2020 08:31

    Levitra 5 Mg Tutti I Giorni <a href=http://apcialisle.com/#>Cialis</a> Finasteride Non Funziona Propecia <a href=http://apcialisle.com/#>Buy Cialis</a> Viagra Achat Paypal

  • said on 10 March 2020 08:29

    On Sale Generic Fedex Macrobid Tablets Medication <a href=http://apcialisle.com/#>Buy Cialis</a> Effet Secondaire Du Cialis <a href=http://apcialisle.com/#>Buy Cialis</a> Cialis Temoignages

  • said on 18 March 2020 05:30

    Zithromax Pack <a href=https://apcialisle.com/#>cheap cialis online</a> Finax Generic Propecia Testicular Pain <a href=https://apcialisle.com/#>cheapest cialis</a> Baby Diahrea And Gas Amoxicillin

  • said on 18 March 2020 21:31

    Brand Name Viagra In Usa <a href=https://apcialisle.com/#>buy cialis</a> Discount Isotretinoin Acne <a href=https://apcialisle.com/#>cialis</a> Cytotec Diu Pharmacie En Ligne

  • said on 24 March 2020 08:57

    Priligy En Quito <a href=https://apcialisle.com/#>Cialis</a> Over The Counter Prednisone At Walmart <a href=https://apcialisle.com/#>buy cialis online from india</a> Where To Purchase Doryx In Internet Worldwide Riverside

Leave a comment

Your email address will not be published. It's only used for gravatars