Articles in this section

How to get pod logs from Kubernetes environment?

Published:

This article outlines the steps to retrieve logs from pods in a Kubernetes namespace.

Prerequisites

Ensure kubectl is installed and configured to access your cluster.

Get the pod logs using the following command

kubectl get pods -n <namespace> 

Example: kubectl get pods -n bold-services

image.png

Use the following command to save logs for each pod into separate .log files

For Powershell (Windows)

kubectl get pods -n <namespace> --no-headers -o custom-columns=":metadata.name" | % { kubectl logs $_ -n {namespace} > "$_.log" } 

Example : kubectl get pods -n bold-services --no-headers -o custom-columns=“:metadata.name” | % { kubectl logs $_ -n bold-services > “$_.log” }

Output reference when you run the command to get the pod logs:

image.png

For Linux

kubectl get pods -n <namespace> --no-headers -o custom-columns=":metadata.name" | while read pod; do kubectl logs "$pod" -n {namespace} > "$pod.log"; done 

Example: kubectl get pods -n bold-services --no-headers -o custom-columns=“:metadata.name” | while read pod; do kubectl logs “$pod” -n bold-services > “$pod.log”; done

image.png

Each pod’s logs will be saved as a separate file named after the pod, as in the image above.

Related help links:

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
DS
Written by Deepikasri Sathiyakandhan
Updated:
Comments (0)
Access denied
Access denied