Kubectl: Get Logs From All Pods

Pod logs are a vital component of any Kubernetes cluster as they contain a detailed record of activities and events that occur inside containers.

During some maintenance or troubleshooting you might want to get logs from all Pods using a kubectl or to watch/follow them in a real-time.

This note shows how to get the logs from all the Pods using the kubectl command and how to monitor them in the real-time.

Cool Tip: Get Pod’s logs using the kubectl command! Read more →

Get Logs From All Pods using Kubectl

Show labels for all Pods and select the common one:

$ kubectl get pods --show-labels
- sample output -
NAME      READY     STATUS    RESTARTS    AGE    LABELS
nginx     1/1       Running    0          10m    app.kubernetes.io/name=web-store,app.kub...
apache-0  1/1       Running    0          10m    app.kubernetes.io/name=web-store,app.kub...
apache-1  1/1       Running    0          10m    app.kubernetes.io/name=web-store,app.kub...
redis     3/3       Running    0          10m    app.kubernetes.io/name=web-store,app.kub...

To get the logs from all the Pods execute the kubectl command with the following options:

$ kubectl logs -l <LABEL> --all-containers --ignore-errors
- example -
$ kubectl logs -l app.kubernetes.io/name=web-store --all-containers --ignore-errors
Option Description
-l, --selector Selector (label query) to filter on
--all-containers Get all containers’ logs in the Pods
--ignore-errors If following Pods logs, allow for any errors that occurs to be non-fatal
-f, --follow Stream the logs

To watch/follow the logs of all the Pods in a real-time, add the -f flag:

$ kubectl logs -l <LABEL> --all-containers --ignore-errors -f

If while trying to follow the logs from all the Pods you receive the error “error: you are attempting to follow 12 log streams, but maximum allowed concurrency is 5“, use --max-log-requests to increase the limit, for example:

$ kubectl logs -l <LABEL> --all-containers --ignore-errors -f --max-log-requests=12

Cool Tip: How to start a Pod and log into it using a kubectl command! Read more →

Was it useful? Share this post with the world!

Leave a Reply