我的应用程序在 K8S pod 中运行。我的应用程序将日志写入我已经在 pod 上安装了卷的特定路径。我的要求是安排 cronjob 每周触发一次并从该 pod 卷中读取日志并根据我的脚本生成报告(这基本上是根据一些关键字过滤日志)。并通过邮件发送报告。不幸的是,我不确定我将如何继续进行,因为我无法获得任何有关将 conrjob 集成到现有 pod 或卷的文档或博客。
apiVersion: v1
kind: Pod
metadata:
name: webserver
spec:
volumes:
- name: shared-logs
emptyDir: {}
containers:
- name: nginx
image: nginx
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx
- name: sidecar-container
image: busybox
command: ["sh","-c","while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done"]
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: "discovery-cronjob"
labels:
app.kubernetes.io/name: discovery
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: log-report
image: busybox
command: ['/bin/sh']
args: ['-c', 'cat /var/log/nginx/access.log > nginx.log']
volumeMounts:
- mountPath: /log
name: shared-logs
restartPolicy: Never