I'm using the handy kubectl logs -l label=value
command to get log from all my pods matching a label. I want to see which pod outputted what log, but only the log text is displayed. Is there a way to control the log format, or a command argument which will let me do this?
These logs can be accessed by adding the -p ( --previous ) flag. Kubectl will then surface the entirety of the stored log for the Pod, including lines that were emitted by containers that have since been terminated.
Checking the logs of a running pod All that you need to do to do that is to run the following command: kubectl logs nginx-7d8b49557c-c2lx9.
Use the --container ( -c ) flag to specify the target container with kubectl logs command. However, in the case of the main container and a sidecar container configuration, the logs you probably want to see in most cases are the main container's. It is troublesome to have to specify the main container every time.
kubectl
now has a --prefix
option that allows you to prefix the pod name before the log message.
Use the awesome kubetail script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With