Skip to content

Naisjob

A Naisjob is very similar to a NAIS Application, except that it only runs once by default. It is built on the Kubernetes Job and CronJob resources. A CronJob runs Jobs on a time-based schedule, as denoted in .spec.schedule.

Restart policies

Naisjobs have restart policies set to "Never", and it is currently not possible to set the restart policy of a Naisjob directly. It is possible to achieve automatic restarts on failure by using startup probes however, though this requires the Pod to expose an HTTP endpoint to answer the probe.

Below you can find a minimal Naisjob example with a schedule for running a Job every minute. If you don't need to have a recurring Naisjob, remove the schedule field from the configuration.

apiVersion: nais.io/v1
kind: Naisjob
metadata:
  labels:
    team: myteam
  name: myjob
  namespace: myteam
spec:
  image: ghcr.io/navikt/myapp:mytag
  schedule: "1/* * * * *"

Warning

If your Naisjob is running in GCP, or if it is using Vault sidecar or Securelogs. You need to shut down all containers running in the pod for the Job to complete. See Shutting down extra containers for more information.

Applying your Naisjob to Kubernetes

You can deploy your Naisjob just as you would deploy your Application using NAIS deploy.

Shutting down extra containers

If your Naisjob has any of these traits:

You will need to shut down all containers running in the pod for the Job to complete.

Shutting down Linkerd

Linkerd exposes an endpoint to shut itself down.

curl -X POST http://127.0.0.1:4191/shutdown
This is done from inside your pod-container.

Securelogs

Securelogs runs on Fluentd, and Fluentd exposes an endpoint to shut itself down.

curl /api/processes.killWorkers
This is done from inside your pod-container.

Vault sidecar

Vault sidecar does not support turning off remotely.