检查日志以获取Kubernetes资源CronJob [英] Check logs for a Kubernetes resource CronJob

查看:71
本文介绍了检查日志以获取Kubernetes资源CronJob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Kubernetes中创建了一个 CronJob 资源.

I created a CronJob resource in Kubernetes.

我想检查日志以验证我的cron是否已运行.但找不到任何方法可以做到这一点.我已经通过了命令,但看起来所有这些都是为了pod资源类型.

I want to check the logs to validate that my crons are run. But not able to find any way to do that. I have gone through the commands but looks like all are for pod resource type.

也尝试关注

$ kubectl logs cronjob/<resource_name>
error: cannot get the logs from *v1beta1.CronJob: selector for *v1beta1.CronJob not implemented

问题:

  1. 如何检查CronJob资源类型的日志?

  1. How to check logs of CronJob Resource type?

如果我希望该资源位于特定的名称空间中,该如何实现呢?

If I want this resource to be in specific namespace, how to implement that same?

推荐答案

您需要检查cronjob创建的pod的日志.吊舱将处于完成状态,但您可以检查日志.

You need to check the logs of the pods which are created by the cronjob. The pods will be in completed state but you can check logs.

# here  you can get the pod_name from the stdout of the cmd `kubectl get pods`
$ kubectl logs -f -n default <pod_name>

要在 namespace 中创建cronjob,只需在 metadata 部分中添加名称空间.吊舱将在该命名空间中创建.

For creating a cronjob in a namespace just add namespace in metadata section. The pods will created in that namespace.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
  namespace: default
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure

理想情况下,您应该将日志发送到日志聚合器系统,例如ELK或Splunk.

Ideally you should be sending the logs to a log aggregator system such as ELK or Splunk.

这篇关于检查日志以获取Kubernetes资源CronJob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆