Jac*_*ack 6 kubernetes kubernetes-cronjob
我在kubernetes中运行cron作业,作业成功完成,我将输出记录到日志文件内部(路径:存储/日志),但是由于容器已完成而无法访问该文件,这是我的工作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
Run Code Online (Sandbox Code Playgroud)
无论如何,我可以在kubectl log命令或其他替代方法上显示我的日志文件内容吗?
Shu*_*rma 11
Cronjob
根据spec.schedule
. 任务完成后,pod 的状态将设置为completed
,但cronjob
控制器在完成后不会删除 pod。并且日志文件内容仍然存在于 pod 的容器文件系统中。所以你需要这样做:
# here you can get the pod_name from the stdout of the cmd `kubectl get pods`
$ kubectl logs -f -n default <pod_name>
Run Code Online (Sandbox Code Playgroud)
我想你知道豆荚像你一样随处可见successfulJobsHistoryLimit: 3
。大概您的意思是您的日志记录将记录到文件而不是stdout,因此您看不到kubectl logs
。如果是这样,也许您还可以登录到stdout或在作业中添加一些内容以最后记录文件的内容,例如在PreStop hook中。
归档时间: |
|
查看次数: |
7960 次 |
最近记录: |