k8s中CronJob的schedule参数

    在k8s中有一种资源叫做CronJob,是一种定时任务的应用,用来定时执行某个任务--具体会在其定义的yaml文件中写出,指定镜像已经执行的脚本命令。 

    如下是定义文件:

apiVersion: batch/v2alpha1

kind: CronJob

metadata:

     name: hello

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

    通过如下命令创建:

$ kubectl create -f cronjob.yaml

# cronjob "hello" created

    也可通过run命令创建CronJob:

kubectl run hello --schedule="*/1 * * * *" --restart=OnFailure --image=busybox -- /bin/sh -c "date; echo Hello from the Kubernetes cluster"

    上述定义文件中,让人不理解的是那个schedule参数,用来定义任务执行的周期,那么,schedule: "*/1 * * * *",这段话到底是什么意思:

这里找到了一个比较靠谱的资料:定时任务CronJob表达式详解

大概内容如下:


CronJob shedule 参数详解

所以我们这里的意思是: 每隔一秒执行一次。

你可能感兴趣的:(k8s中CronJob的schedule参数)