在每个节点上创建一个pod(守护进程)apiVersion: apps/v1 kind: DaemonSet metadata: name: ssd-monitor spec: selector: matchLabels: app: ssd-monitor template: metadata: labels: app: ssd-monitor spec: nodeSelector: disk: ssd containers: - name: main image: luksa/ssd-monitor
kubectl get ds // 显示DaemonSet
Job //执行单个任务的podapiVersion: batch/v1 kind: Job metadata: name: batch-job spec: template: metadata: labels: app: batch-job spec: containers: - name: main image: luksa/batch-job restartPolicy: OnFailure
restartPolicy需要指定OnFailure 或者Never,因为restartPolicy 默认为Alwways.由于Job只能执行一次,所以必须指定.
apiVersion: batch/v1 kind: Job metadata: name: multi-completion-batch-job spec: completions: 5 parallelism: 2 template: metadata: labels: app: batch-job spec: schedule: "0,15,30,45 * * * *" restartPolicy: OnFailure containers: - name: main image: luksa/batch-job
completions: 5 //一个接一个运行5个pod.当前pod运行完成后创建第二个
parallelism: 2 // 允许两个pod并行运行,一pod运行完成后创建下一个
kubectl edit job multi-completion-batch-job //修改job
其中 backoffLimit: 6 // job被标记为失败前的重试可以次数.默认为6
schedule: "0,15,30,45 * * * *" // 每15分钟执行一次,每小时,每天,每月,每周