Seems that kubectl logs doesn't support cronjob. It says
error: cannot get the logs from *v1beta1.CronJob: selector for *v1beta1.CronJob not implemented
Currently I check the logs of all relative jobs one by one.
Is there any simple command or tool to get these logs?
I did some research on bash script and modified edbighead's answer to better suit my needs.
# cronJobGetAllLogs.sh: Get all logs of a cronjob.
# example:
# ./cronJobGetAllLogs.sh [Insert name of cronJob]
jobs=( $(kubectl get jobs --no-headers -o custom-columns=":metadata.name" | awk "/$1-[0-9]+/{print \$1}" | sort -r ) )
for job in "${jobs[@]}"
do
echo Logs from job $job
pod=$(kubectl get pods -l job-name=$job --no-headers -o custom-columns=":metadata.name")
kubectl logs $pod
done
# cronJobGetLatestLog.sh: Get log of latest job initiated by a cronjob.
# example:
# ./cronJobGetLateestLog.sh [Insert name of cronJob]
job=$(kubectl get jobs --no-headers -o custom-columns=":metadata.name" | awk "/$1-[0-9]+/{print \$1}" | sort -r | head -1)
pod=$(kubectl get pods -l job-name=$job --no-headers -o custom-columns=":metadata.name")
kubectl logs $pod
所有评论(0)