How do I retain/access the custom log files from a completed cronjob?

8/7/2017

I have a cronjob that is completing and outputting several log files.

I want to persist these files and be able access them after the pod has succeeded.

I've found I can access the stdout with oc logs -f <pod>, but I really need to access the log files.

I'm aware Openshift 2 apparently had an environment variable location OPENSHIFT_LOG_DIR that log files were written to, but Openshift 3.5 doesn't appear to have this.

What's my best way of logging and accessing the logs from the CronJob after the pod has succeeded and finished?

-- James
kubernetes
openshift

1 Answer

8/9/2017

After a Job runs to completion, the Pod terminates, but it is not automatically deleted. Since it has completed, you need to use -a to see it. Once you have the Pod name, kubectl logs works as you would expect.

$ kubectl get pods -a
NAME                                    READY     STATUS      RESTARTS   AGE
curator-1499817660-6rzmf                0/1       Completed   0          28d
$ kubectl logs curator-1499817660-6rzmf
2017-07-12 00:01:10,409 INFO ...
-- coreypobrien
Source: StackOverflow