How to run batch job on azure kubernetes

7/9/2020

What is the simplest way to run a containerized batch job written in C# on Azure Kubernetes Service?

This question is geared specifically towards AKS. So, I am not looking for it run as Azure Container Instance or in a Serverless manner within Azure.

-- GilliVilla
azure
azure-aks
c#
kubernetes

1 Answer

7/9/2020

You can use kubernetes job.

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.

Here is an example Job config. It computes π to 2000 places and prints it out. It takes around 10s to complete.

apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4

If you want to run the batch job on a repeating schedule then use kubernetes cronjob

-- Arghya Sadhu
Source: StackOverflow