Kubernetes - how to run job only once

后端 未结 3 1236
一向
一向 2020-12-30 21:08

I have a job definition based on example from kubernetes website.

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-timeout-6
spec:
  activeDeadlineSe         


        
相关标签:
3条回答
  • 2020-12-30 21:37

    If you want a one-try command runner, you probably should create bare pod, because the job will try to execute the command until it's successful or the active deadline is met.

    Just create the pod from your template:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pi
    spec:
      containers:
      - name: pi
        image: perl
        command: ["exit", "1"]
      restartPolicy: Never
    
    0 讨论(0)
  • 2020-12-30 21:43

    By now this is possible by setting backoffLimit: 0 which tells the controller to do 0 retries. default is 6

    0 讨论(0)
  • 2020-12-30 21:58

    Sadly there is currently no way to prevent the job controller to just respawn new pods when they fail, but the kubernetes community is working on a solution, see:

    "Backoff policy and failed pod limit" https://github.com/kubernetes/community/pull/583

    0 讨论(0)
提交回复
热议问题