许吉友 - 运维

使用扩展进行并行处理

apiVersion: batch/v1
kind: Job
metadata:
  name: process-item-$ITEM
  labels:
    jobgroup: jobexample
spec:
  template:
    metadata:
      name: jobexample
      labels:
        jobgroup: jobexample
    spec:
      containers:
      - name: c
        image: busybox
        command: ["sh", "-c", "echo Processing item $ITEM && sleep 5"]
      restartPolicy: Never
# Expand files into a temporary directory
$ mkdir ./jobs
$ for i in apple banana cherry
do
  cat job-tmpl.yaml | sed "s/\$ITEM/$i/" > ./jobs/job-$i.yaml
done
$ kubectl create -f ./jobs
$ kubectl get jobs -l jobgroup=jobexample
$ kubectl get pods -l jobgroup=jobexample
$ for p in $(kubectl get pods -l jobgroup=jobexample -o name)
do
  kubectl logs $p
done