zoukankan      html  css  js  c++  java
  • Creating a Cron Job in K8S

    Creating a Cron Job

    Cron jobs require a config file. This example cron job config .spec file prints the current time and a hello message every minute:

    application/job/cronjob.yaml 
    apiVersion: batch/v1beta1
    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
    

    Run the example cron job by downloading the example file and then running this command:

    $ kubectl create -f ./cronjob.yaml
    cronjob "hello" created

    Alternatively, you can use kubectl run to create a cron job without writing a full config:

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

    After creating the cron job, get its status using this command:

    $ kubectl get cronjob hello
    NAME      SCHEDULE      SUSPEND   ACTIVE    LAST-SCHEDULE
    hello     */1 * * * *   False     0         <none>

    As you can see from the results of the command, the cron job has not scheduled or run any jobs yet. Watch for the job to be created in around one minute:

    $ kubectl get jobs --watch
    NAME               DESIRED   SUCCESSFUL   AGE
    hello-4111706356   1         1         2s

    Now you’ve seen one running job scheduled by the “hello” cron job. You can stop watching the job and view the cron job again to see that it scheduled the job:

    $ kubectl get cronjob hello
    NAME      SCHEDULE      SUSPEND   ACTIVE    LAST-SCHEDULE
    hello     */1 * * * *   False     0         Mon, 29 Aug 2016 14:34:00 -0700

    You should see that the cron job “hello” successfully scheduled a job at the time specified in LAST-SCHEDULE. There are currently 0 active jobs, meaning that the job has completed or failed.

    Now, find the pods that the last scheduled job created and view the standard output of one of the pods. Note that the job name and pod name are different.

    # Replace "hello-4111706356" with the job name in your system
    $ pods=$(kubectl get pods --selector=job-name=hello-4111706356 --output=jsonpath={.items..metadata.name})
    
    $ echo $pods
    hello-4111706356-o9qcm
    
    $ kubectl logs $pods
    Mon Aug 29 21:34:09 UTC 2016
    Hello from the Kubernetes cluster

     https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/

  • 相关阅读:
    (OnTouchListener) android中的触摸事件的使用(绘图)
    Android开发问题:ActivityNotFoundException: Unable to find explicit activity class
    自定义控件view,并且使用滚动条
    Android中常用的UI控件
    Android中解析XML数据存储
    也许有你的身影
    Android中动态图形的绘制
    治疗失眠十种食疗方
    深入理解iPhone屏幕双缓冲技术
    非苹果PC安装MacOS
  • 原文地址:https://www.cnblogs.com/oskb/p/10244470.html
Copyright © 2011-2022 走看看