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?
OpenShift Container Platform uses Fluentd to collect container and node logs. By default, the log collector uses the following sources: journald for all system logs. /var/log/containers/*.
To copy files from the container to the local machine, you can use the oc rsync command. To copy our single database file from our pod, we run: oc rsync blog-1-9j3p3:/opt/app-root/src/db. sqlite3 .
These logs are usually located in the /var/log/containers directory on your host. If a container restarts, kubelet keeps logs on the node. To prevent logs from filling up all the available space on the node, Kubernetes has a log rotation policy set in place.
You can view the logs for various resources, such as builds, deployments, and pods by using the OpenShift CLI (oc) and the web console. Resource logs are a default feature that provides limited log viewing capability. To enhance your log retrieving and viewing experience, it is recommended that you install OpenShift Logging.
Just Check if it connects to POD and do some ls -lh (it should give some response) Extract the oc login command. Login into oc using login command on cli client. Navigate to namespace where pod is hosted -> oc project project-name Log file is generated in the current directory.
The oc logs pod/<pod name> command can be used to view a pods log. The -f or --follow option can be used to stream the log in real time. The -p or --previous flag can be used to see previous logs.
Login into oc using login command on cli client. Navigate to namespace where pod is hosted -> oc project project-name Log file is generated in the current directory. oc cp <namespace>/<pod>:<myFolder> .
You can copy files in and out of pods using the rsync command.
Or use the logs
command like you are and just redirect to a file so you can edit it locally:
oc logs <podname> &> /path/to/file
From your oc CLI tool execute:
oc logs pod_name -n project_name > filename.log
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
Without specifying the namespace the copy command will not work (and display no error message), so I had to which project the pod belongs.
<pod>
is the pod name<namespace>
is actually the project the <pod>
belongs to.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
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