Job

第一个Job清单文件

# cat job-demo.yaml 
apiVersion: batch/v1
kind: Job
metadata:
  name: do-something
spec:
  template:
    spec:
      containers:
      - name: do-something-container
        image: busybox:latest
        command: ["wget", "-q", "-O", "-", "http://1.1.1.1/index.html"]
      restartPolicy: Never
  backoffLimit: 3

创建Job并获取状态

# kubectl apply -f job-demo.yaml
job.batch/do-something created
# kubectl get job -o wide
NAME           DESIRED   SUCCESSFUL   AGE       CONTAINERS               IMAGES           SELECTOR
do-something   1         1            5m        do-something-container   busybox:latest   controller-uid=336448fd-b0e1-11e8-8b6e-00163e08c384
# kubectl describe job do-something
Name:           do-something
Namespace:      default
Selector:       controller-uid=336448fd-b0e1-11e8-8b6e-00163e08c384
Labels:         controller-uid=336448fd-b0e1-11e8-8b6e-00163e08c384
                job-name=do-something
Annotations:    kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"do-something","namespace":"default"},"spec":{"backoffLimit":3,"template":{"s...
Parallelism:    1
Completions:    1
Start Time:     Wed, 05 Sep 2018 15:56:31 +0800
Pods Statuses:  0 Running / 1 Succeeded / 0 Failed
Pod Template:
  Labels:  controller-uid=336448fd-b0e1-11e8-8b6e-00163e08c384
           job-name=do-something
  Containers:
   do-something-container:
    Image:      busybox:latest
    Port:       <none>
    Host Port:  <none>
    Command:
      wget
      -q
      -O
      -
      http://1.1.1.1/index.html
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------
  Normal  SuccessfulCreate  42s   job-controller  Created pod: do-something-p7jhn

获取执行结果输出

# kubectl get pod -o wide
NAME                     READY     STATUS      RESTARTS   AGE       IP            NODE
client-bbf58867f-tzxhf   1/1       Running     2          2d        10.244.1.12   node002
do-something-p7jhn       0/1       Completed   0          5m        10.244.2.24   node003
# kubectl logs do-something-p7jhn
HAHAHA.

results matching ""

    No results matching ""