ddttdd
ddttdd

Reputation: 131

Export logs of Kubernetes cronjob to a path after each run

I currently have a Cronjob that has a job that schedule at some period of time and run in a pattern. I want to export the logs of each pod runs to a file in the path as temp/logs/FILENAME with the FILENAME to be the timestamp of the run being created. How am I going to do that? Hopefully to provide a solution. If you would need to add a script, then please use python or shell command. Thank you.

Upvotes: 0

Views: 1224

Answers (2)

Wytrzymały Wiktor
Wytrzymały Wiktor

Reputation: 13878

According to Kubernetes Logging Architecture:

In a cluster, logs should have a separate storage and lifecycle independent of nodes, pods, or containers. This concept is called cluster-level logging.

Cluster-level logging architectures require a separate backend to store, analyze, and query logs. Kubernetes does not provide a native storage solution for log data. Instead, there are many logging solutions that integrate with Kubernetes.

Which brings us to Cluster-level logging architectures:

While Kubernetes does not provide a native solution for cluster-level logging, there are several common approaches you can consider. Here are some options:

  • Use a node-level logging agent that runs on every node.

  • Include a dedicated sidecar container for logging in an application pod.

  • Push logs directly to a backend from within an application.

Kubernetes does not provide log aggregation of its own. Therefore, you need a local agent to gather the data and send it to the central log management. See some options below:

Upvotes: 1

Dragan Bocevski
Dragan Bocevski

Reputation: 51

You can find all logs that PODs are generating at /var/log/containers/*.log on each Kubernetes node. You could work with them manually if you prefer, using simple scripts, but you will have to keep in mind that PODs can run on any node (if not restricted), and nodes may come and go.

Consider sending your logs to an external system like ElasticSearch or Grafana Loki and manage them there.

Upvotes: 1

Related Questions