Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

AK DevCraft
AK DevCraftSubscriber

Posted on • Edited on

     

Streaming logs of all pods at once

If you're like me who likes to see all of the log events in a single terminal then you're at right place. In this article we see how to view logs of single container pod with multiple replicas, logs of a particular container of a multi containers pod and logs of all containers of a multi containers pod. Here are the list of commands:

1. Stream logs of single container pod with multiple replicas

In Kubernetes it's all about labels and selectors. And I'm going to demonstrate commands using labels. In case you are not familiar with how to get label details from a pod or how to add label on a pod then jump to the end of this post.

Note: I prefer using alias, here 'k' is alias for kubectl. set it asalias k=kubectl

k logs -f -l <pod-label-value> --prefix
Enter fullscreen modeExit fullscreen mode

Note:--prefix Prefix each log line with log source (pod and container names)

E.g.

k logs -f -l app-name=example-app --prefix
Enter fullscreen modeExit fullscreen mode

Note: hereapp-name=example-app label is on the pod. If you would like to stream logs from multiple pods from different application deployments within a namespace, then use a common label that’s present across all pods, or add a such label.

2. Stream logs of a particular container of a multi-containers pod with multiple replicas

k logs -f -l <pod-label-value> --prefix -c <container-name>
Enter fullscreen modeExit fullscreen mode

E.g.

k logs -f -l app-name=example-app --prefix -c example-conn
Enter fullscreen modeExit fullscreen mode

Note: hereapp-name=example-app label is on the pod, andexample-conn is the container name.

3. Stream logs of all containers of a multi-containers pod with multiple replicas

a. Using label

k logs -f -l <pod-label-value> --prefix -all-containers
Enter fullscreen modeExit fullscreen mode

E.g.

k logs -f -l app-name=example-app --prefix -all-containers
Enter fullscreen modeExit fullscreen mode

b. Using deployment name

k logs -f deploy/<deployment-name> --prefix -all-containers
Enter fullscreen modeExit fullscreen mode

E.g.

k logs -f deply/example-deployment --prefix -all-containers
Enter fullscreen modeExit fullscreen mode

4. Show labels associated with a pod

k get po <pod-name> --show-labels
Enter fullscreen modeExit fullscreen mode

5. Add label on running pod

k label po <pod-name> app-name=example-app
Enter fullscreen modeExit fullscreen mode

If you have reached here, then I made a satisfactory effort to keep you reading. Please be kind enough to leave any comments or ask for any corrections. Happy Kuberneting!

Other Blogs:

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full-Stack Software Engineer, creating digital solutions across various platforms. Programming and software engineering are essential part of my life just like air 😎
  • Work
    Software Engineer
  • Joined

More fromAK DevCraft

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp