k8s都job控制器用于执行单次任务
可以设置运行次数,失败重试的次数,以及并行数
查看job都情况

kubectl describe jobs.batch echo-time
Name:           echo-time
Namespace:      default
Selector:       controller-uid=499e13dc-eae6-477f-98b8-84d27a738797
Labels:         controller-uid=499e13dc-eae6-477f-98b8-84d27a738797
                job-name=echo-time
Annotations:    <none>
Parallelism:    1
Completions:    1
Start Time:     Sun, 31 Jan 2021 13:17:47 +0800
Completed At:   Sun, 31 Jan 2021 13:19:29 +0800
Duration:       102s
Pods Statuses:  0 Running / 1 Succeeded / 0 Failed
Pod Template:
  Labels:  controller-uid=499e13dc-eae6-477f-98b8-84d27a738797
           job-name=echo-time
  Containers:
   echo-time:
    Image:      centos:latest
    Port:       <none>
    Host Port:  <none>
    Command:
      /bin/bash
      -c
      for i in `seq 1 100`;do echo ${date} && sleep 1;done
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age    From            Message
  ----    ------            ----   ----            -------
  Normal  SuccessfulCreate  7m34s  job-controller  Created pod: echo-time-247gc
  Normal  Completed         5m52s  job-controller  Job completed
[root@node-1 ~]# 

[root@node-1 ~]# kubectl get jobs.batch
NAME COMPLETIONS DURATION AGE
echo-time 1/1 102s 4m11s


apiVersion: batch/v1
kind: Job
metadata:
  name: echo-time
spec:
  completions: 10 #任务个数
  parallelism: 1 #并行数
  backoffLimit: 2 #失败最多执行几次
  template:
    spec:
      containers:
      - name: echo-time
        image: centos:latest
        imagePullPolicy: IfNotPresent
        command:
        - /bin/bash
        - "-c"
        - "for i in `seq 1 100`;do echo `date` && sleep 1;done"
      restartPolicy: OnFailure                                    
查看pod情况
[root@node-1 ~]# kubectl get pods
NAME                             READY   STATUS    RESTARTS   AGE
app-demo-6b476b769d-4rtkb        1/1     Running   6          6d21h
app-demo-6b476b769d-5jlds        1/1     Running   3          3d16h
app-demo-6b476b769d-5l7tn        1/1     Running   3          3d16h
cpu-demo                         1/1     Running   2          2d17h
dashboard-demo-86d6f7bb4-dht22   1/1     Running   5          5d16h
dashboard-demo-86d6f7bb4-j8c8c   1/1     Running   5          5d16h
dashboard-demo-86d6f7bb4-w5k6t   1/1     Running   3          3d16h
echo-time-86wpp                  1/1     Running   0          19s
memory-demo                      1/1     Running   2          2d17h
replicaset-demo-dpfrq            1/1     Running   1          41h
replicaset-demo-vk48s            1/1     Running   1          41h
replicaset-demo-xz5n6            1/1     Running   1          41h
查看pod日志
[root@node-1 ~]# kubectl logs  echo-time-86wpp 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐