kubernetes集群系列资料10--job/cronjob介绍

一、job/cronjob案例

##########K8S案例5---job#############

vim job.yaml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apiVersion: batch/v1
kind: Job
metadata:
    name: job
spec:
    template:                           #以下为嵌套pod的字段;
        metadata:
            name: job
        spec:
            containers:
            - name: job
              image: perl
              command: ["perl","-Mbignum=bpi","-wle","print bpi(2000)"]
            restartPolicy: Never
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kubectl apply -f job.yaml
kubectl get job;kubectl get pod -o wide        #查看创建的daemonset及pod;pod状态为completed,表示pod已执行完job;
kubectl logs job-ml5ls      #查看执行print bpi(2000)结果;

##########K8S案例5---job#############


##########K8S案例6---cronjob#############
vim cronjob.yaml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apiVersion: batch/v1beta1
kind: CronJob
metadata:
    name: cronjob
spec:
    schedule: "*/1 * * * *"
    jobTemplate:
        spec:
            template:
                spec:
                    containers:
                    - name: cronjob
                      image: hub.atguigu.com/library/busybox:latest
                      args:
                      - /bin/sh
                      - -c
                      - date;echo hello from k8s cluster
                    restartPolicy: OnFailure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kubectl apply -f cronjob.yaml
kubectl get cronjob                     #查看创建cronjob;
kubectl get pod                         #查看pod执行情况;
kubectl logs cronjob-1623763560-tpd4z   #查看pod执行日志;

##########K8S案例6---cronjob#############

  

posted on 2021-06-17 22:42  chalon  阅读(69)  评论(0编辑  收藏  举报