??? 在k8s中有一種資源叫做CronJob,是一種定時任務的應用,用來定時執(zhí)行某個任務--具體會在其定義的yaml文件中寫出,指定鏡像已經(jīng)執(zhí)行的腳本命令。?
??? 如下是定義文件:
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
??? 通過如下命令創(chuàng)建:
$ kubectl create -f cronjob.yaml
# cronjob "hello" created
??? 也可通過run命令創(chuàng)建CronJob:
kubectl run hello --schedule="*/1 * * * *" --restart=OnFailure --image=busybox -- /bin/sh -c "date; echo Hello from the Kubernetes cluster"
??? 上述定義文件中,讓人不理解的是那個schedule參數(shù),用來定義任務執(zhí)行的周期,那么,schedule: "*/1 * * * *",這段話到底是什么意思:
這里找到了一個比較靠譜的資料:定時任務CronJob表達式詳解
大概內(nèi)容如下:

所以我們這里的意思是: 每隔一秒執(zhí)行一次。