Reputation: 855
I have my spring boot application running on Openshift as container built using docker Image. I have enabled the logging in my application and prints all the logs.
Now i want to examine the log files of the POD to check for any errors, since one my request is failing. I do know about the command line option oc logs -f <podname>
That just prints the log into cmd prompt, but i want whole log to be copied from server to local file.
So that i can find some particular lines or errors. Is is possible?
Upvotes: 8
Views: 59680
Reputation: 41
The oc logs
command knows where to find the log files of your pod so you do not need to specify a log file location/path within the command.
Use the following command to copy the log for a specified project and pod to the local directory where you are running this command:
oc logs [pod_name] -n [project_name] > [outputFilename].log
Upvotes: 4
Reputation: 1306
Try oc rsync
as suggested above:
oc rsync <pod>:/path/to/file localfilename
However in my case I got:
WARNING: cannot use rsync: rsync not available in container <pod>
So I tried try oc cp
, and it worked:
oc cp <namespace>/<pod>:/path/to/file local_filename
<pod>
is the pod name<namespace>
is actually the project the <pod>
belongs to.Without specifying the namespace the copy command will not work (and display no error message), so I had to find out which project the pod belongs.
oc project
to list current project, oroc projects
to list all projectsoc get pods --all-namespaces | egrep <pod>
# !!!Important Note!!!
# Requires that the 'tar' binary is present in your container
# image. If 'tar' is not present, 'kubectl cp' will fail.
# about my environment
# oc version
# oc 3.6, openshift 3.7, kubernetes 1.7
OpenShift 4.3 Oficial Documentation - copying files
Upvotes: 5
Reputation: 1
for me the way it works was to copy the folder with the logs I was intended to get from my pod to the default path were the pod sent you when you login in the pod and then apply:
oc cp <namespace>/<pod>:<myFolder> .
Upvotes: 0
Reputation: 1
Log file is generated in the current directory.
Upvotes: 0
Reputation: 291
To download the file from fabric pod to your local machine
oc login url--token=<token>>
oc rsh <podname>
Just Check if it connects to POD and do some ls -lh(it should give some response)
oc rsync <podname>:<path>/logs.txt localfilename
Upvotes: 0
Reputation: 309
login from oc cli tools, then switch to project, execute:
oc logs <podname> >> <podname>.log
Upvotes: 0
Reputation: 4703
That just prints the log into cmd prompt, but i want whole log to be copied from server to local file. So that i can find some particular lines or errors. Is is possible?
What about check /var/log/containers
on the node which pods are running ?
There are all container logs which are symbolic links as <pod name>_<namespace>_<container name>-<hash>
format. Basically, oc logs
also refers the same container logs at there.
e.g.>
node ~# ls -1 /var/log/containers
alertmanager-main-0_openshift-monitoring_alertmanager-123...789.log
alertmanager-main-0_openshift-monitoring_alertmanager-456...123.log
alertmanager-main-0_openshift-monitoring_alertmanager-proxy-789...456.log
...
Upvotes: 2