访问cron作业kubernetes中的日志 [英] access logs in cron jobs kubernetes
问题描述
我在kubernetes中运行cron作业,作业成功完成,我将输出记录到日志文件中(路径:存储/日志),但是由于容器已完成而无法访问该文件,这是我的工作Yaml.
im running cron job in kubernetes, jobs completes successfully and i log output to log file inside(path: storage/logs) but i cannot access that file due to container is in completed here is my job yaml.
apiVersion: v1
items:
- apiVersion: batch/v1beta1
kind: CronJob
metadata:
labels:
chart: cronjobs-0.1.0
name: cron-cronjob1
namespace: default
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
metadata:
labels:
app: cron
cron: cronjob1
spec:
containers:
- args:
- /usr/local/bin/php
- -c
- /var/www/html/artisan bulk:import
env:
- name: DB_CONNECTION
value: postgres
- name: DB_HOST
value: postgres
- name: DB_PORT
value: "5432"
- name: DB_DATABASE
value: xxx
- name: DB_USERNAME
value: xxx
- name: DB_PASSWORD
value: xxxx
- name: APP_KEY
value: xxxxx
image: registry.xxxxx.com/xxxx:2ecb785-e927977
imagePullPolicy: IfNotPresent
name: cronjob1
ports:
- containerPort: 80
name: http
protocol: TCP
imagePullSecrets:
- name: xxxxx
restartPolicy: OnFailure
terminationGracePeriodSeconds: 30
schedule: '* * * * *'
successfulJobsHistoryLimit: 3
反正我可以在kubectl log命令或其他替代方法上显示我的日志文件内容吗?
is there anyway i can get my log file content display on kubectl log command or other alternatives?
推荐答案
我想您知道,当您拥有successfulJobsHistoryLimit: 3
时,豆荚就被保存在身边.大概您的意思是您的日志记录将记录到文件而不是stdout,因此您不会在kubectl logs
中看到它.如果是这样,也许您也可以登录到stdout或在作业中添加一些内容以最后记录文件的内容, PreStop钩子.
I guess you know that the pod is kept around as you have successfulJobsHistoryLimit: 3
. Presumably your point is that your logging is going logged to a file and not stdout and so you don't see it with kubectl logs
. If so maybe you could also log to stdout or put something into the job to log the content of the file at the end, for example in a PreStop hook.
这篇关于访问cron作业kubernetes中的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!