Tip: Export all Kubernetes container logs

  • 5 October 2022
  • 1 reply
  • 238 views

Userlevel 7
Badge +18

I got lazy and was sick of remembering or typing namespace and pod names. Enjoy.

 

get_all_pod_logs.ps1

#!pwsh
$all_pods = kubectl get pods --all-namespaces -o json | ConvertFrom-JSon
ForEach ($pod In $all_pods.items) {
$ns = $pod.metadata.namespace
$pod_name = $pod.metadata.name
ForEach ($container In $pod.spec.containers) {
$container_name = $container.name
$file_name = "$($ns)_$($pod_name)_$($container_name).log"
kubectl -n $ns logs $pod_name -c $container_name | Out-File $file_name
$file_name
}
}

 


1 reply

Userlevel 7
Badge +20

Hi Kevin,

You can also use the mtctl dump for this. 

MTCTL - Middletier Controller - Technical Documentation For IFS Cloud

 

Thanks,

Kasun

Reply