我的应用程序在K8S 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
最佳答案
我在这里看到两件事,您需要了解: