One-time Jobs

How to run one-off jobs with Opta

On occasion one may wish to run one-time jobs for their application, e.g. to run migrations. This can currently be achieved with opta by using the helm chart module to create a helm chart which runs the one-time job. For example, the following yaml will create a one-time job using the image busybox and run the command /bin/sh -c "date; echo Hello from the Kubernetes cluster":

# hello-cron.yaml
name: hello-job
  - name: staging
    path: "opta.yaml"
  - type: helm-chart
    namespace: hello # Note that this will run in the "hello" namespace
    create_namespace: true # In this example, the "hello" namespace is not pre-existing so we must create it.
    # see for reference
    chart: job
    chart_version: 1.0.0
      restartPolicy: Never
          image: busybox
              - name: ENVAR
                value: VALUE1
              - /bin/sh
              - -c
              - date; echo Hello from the Kubernetes cluster

The job will now be run as part of the next opta apply/deploy. You can monitor the progress of this job by inspecting the pod created for this job like so:

$ kubectl get pods -n hello-job
NAME                        READY   STATUS      RESTARTS   AGE
hello-job-helmchart-jnwx9   0/1     Completed   0          4h46m
$ kubectl logs -n hello-job hello-job-helmchart-jnwx9
Thu Mar  3 01:37:31 UTC 2022
Hello from the Kubernetes cluster4

Last modified August 5, 2022 : Cleanup install script (#197) (2175394)