Is it possible to obtain Kubernetes logs for a dedicated time range?
Yes, it is possible and in many different ways.
The only thought is to attach some external service like Kibana for the logs collection, but maybe built-in Kubernetes remedies allow to do this?
Both are possible. However, it all depends on the specific case which will be better. Chris Doyle put it well in his comment:
it would depend on your log retention and roll over strategy you have in your cluster, generally you would need to consider node space especially when nodes are running multiple pods etc. Generally speaking my preferred strategy is to have short retention period on the node side and push log off to a centralised solution like you mentioned with elk, splunk, datadog, loki etc
Of course, the built-in k8s tools will also be able to help you. You have to use kubectl logs
with the proper flags. You can read about all options in the manual:
This could be the most interesting part:
--since=0: Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of since-time / since may be used.
--since-time="": Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used.
To display pod logs from the last week, you can run the following command:
kubectl logs -n <pod_namespace (optional)> <pod name> --since 168h