14

From the question you can tell I'm a newb.

At the moment to get the logs of my pod I'm doing a ...

oc logs -f api-myapp-v1-48-cdrs2

This shows me everything in the log. How can I tail them instead?

Also I was wodering if someone could point me out to a nice cheat sheet of open shift commands? One that is good for beginners.

thanks

Richie
  • 4,989
  • 24
  • 90
  • 177

2 Answers2

25

Use the --tail option.

oc logs api-myapp-v1-48-cdrs2 --tail=50

You can use the --help option to commands to find out what options they accept.

For some hands on exercises to help you learn OpenShift, see:

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • Those interactive tutorials are awesome! Exactly what I was looking for. Thank you. – Richie Jul 24 '17 at 04:47
  • Keep returning to learn.openshift.com. We will continually be adding more exercises over time. – Graham Dumpleton Jul 24 '17 at 05:09
  • Is there a way to tail log of all pods of a particular service? – Michal Foksa Mar 13 '18 at 07:41
  • From the command line only by tailing each pod. If your OpenShift installation has aggregated logging installed, then you can use that from the web console to watch logs across whole application. – Graham Dumpleton Mar 13 '18 at 07:47
  • Hmm, I have running one pod of a `my-service`. With `oc logs -f --tail=50 dc/my-service` I have got log of that pod. I will try to spin up multiple pods and see. – Michal Foksa Mar 13 '18 at 08:11
  • Just tested it with 2 pods running. I have got messages only from the fist created pod. :(. – Michal Foksa Mar 13 '18 at 08:45
  • Which is what monitoring logs of ``dc`` will do. As I said, you need to run ``oc logs`` on each pod. There is really no other way from the command line. – Graham Dumpleton Mar 13 '18 at 09:55
  • Hmmm :( Can request the feature somewhere ? – Michal Foksa Mar 13 '18 at 10:40
  • The capability is provided by the aggregated logging feature available through the web console. Have you setup aggregated logging for your cluster? – Graham Dumpleton Mar 13 '18 at 10:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/166750/discussion-between-michal-foksa-and-graham-dumpleton). – Michal Foksa Mar 13 '18 at 11:09
  • 1
    There is nothing else I can tell you. Read the documentation is the best thing you can do to learn about it and steps necessary to set it up. https://docs.openshift.com/container-platform/3.7/install_config/aggregate_logging.html From the web console, if you do have it, click ob 'View Archive' on top right just above log window for a pod. – Graham Dumpleton Mar 13 '18 at 12:07
6

use -f along with tail, that will work

oc logs -f api-myapp-v1-48-cdrs2 --tail=5
Murugesh
  • 121
  • 1
  • 4