kubernetes_job_v1

A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions. When a specified number of successful completions is reached, the task (ie, Job) is complete. Deleting a Job will clean up the Pods it created.

A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted (for example due to a node hardware failure or a node reboot.

You can also use a Job to run multiple Pods in parallel.

Example Usage - No waiting

resource "kubernetes_job_v1" "demo" {
  metadata {
    name = "demo"
  }
  spec {
    template {
      metadata {}
      spec {
        container {
          name    = "pi"
          image   = "perl"
          command = ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
        }
        restart_policy = "Never"
      }
    }
    backoff_limit = 4
  }
  wait_for_completion = false
}

Example Usage - waiting for job successful completion

resource "kubernetes_job_v1" "demo" {
  metadata {
    name = "demo"
  }
  spec {
    template {
      metadata {}
      spec {
        container {
          name    = "pi"
          image   = "perl"
          command = ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
        }
        restart_policy = "Never"
      }
    }
    backoff_limit = 4
  }
  wait_for_completion = true
  timeouts {
    create = "2m"
    update = "2m"
  }
}

Argument Reference

The following arguments are supported:

Nested Blocks

metadata

Arguments

Attributes

spec

Arguments

pod_failure_policy

Arguments

rule

Arguments

on_exit_codes

Arguments

on_pod_condition

Arguments

selector

Arguments

template

Arguments

These arguments are the same as the for the spec block of a Pod.

Please see the Pod resource for reference.

Timeouts

The following Timeout configuration options are available for the kubernetes_job_v1 resource when used with wait_for_completion = true:

Note: