Press "Enter" to skip to content

Tail logs from multiple pods simultaneously in Kubernetes

I’ve recently started working quite extensively with Kubernetes on Google Container Engine. But one thing that bugged me was that I couldn’t get logs from multiple pods simultaneously using the Google Cloud SDK (kubectl). This is something that you often want to do, at least if you run multiple instances of a pod behind a replication controller. This is especially true when experimenting with Kubernetes and you don’t have Kibana or similar setup (with Kubernetes 1.0 it’s not easy to get logs from multiple pods using the Google Cloud Logging interface either although this should improve in version 1.1, see here). So before the tooling catches up I decided to write a little bash script that allows you to tail multiple pods simultaneously in an easy manner. The script is called kubetail and is available at github.

Usage

First find the names of all your pods:

This will return a list looking something like this:

To tail the logs of the two “app2” pods in one go simply do:

You’ll now get the logs streamed for all pods containing “app2”.

Known issues

When you press “ctrl+c” to end the log session you may end up with errors like this:

I’m not quite sure why this happens, pull requests are welcome 🙂

2 Comments

  1. builder builder November 9, 2016

    very handy.. thx!

  2. sambit sambit May 28, 2017

    thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *