How in kubernetes save pod logs from a period of time. I can render logs like kubectl logs POD_NAME, but how to save them to a file?
In your application pod write logs to path in filesystem using a volumeMounts
.
From the docs here use a sidecar container with a logging agent such as fluentbit to send logs written to the filesystem to a centralized logging backend such as splunk or Elasticsearch.
apiVersion: apps/v1
kind: Deployment
metadata:
name: fluentbit-logging-sidecar
spec:
selector:
matchLabels:
app: fluentbit-logging-sidecar
replicas: 1
template:
metadata:
labels:
app: fluentbit-logging-sidecar
volumes:
- name: shared-data
emptyDir: {}
- name: config-volume
configMap:
name: fb-agent-config
containers:
- name: sample-logging
image: <image>
volumeMounts:
- name: shared-data
mountPath: /app/logs
- name: fb-sidecar
image: fluent/fluent-bit
volumeMounts:
- name: shared-data
mountPath: /app/logs
- name: config-volume
mountPath: /fluent-bit/etc/fluent-bit.conf
subPath: fluent-bit.conf