简体   繁体   English

如何在 azure kubernetes 上运行批处理作业

[英]How to run batch job on azure kubernetes

What is the simplest way to run a containerized batch job written in C# on Azure Kubernetes Service?在 Azure Kubernetes 服务上运行用 C# 编写的容器化批处理作业的最简单方法是什么?

This question is geared specifically towards AKS.这个问题专门针对 AKS。 So, I am not looking for it run as Azure Container Instance or in a Serverless manner within Azure.所以,我不是在寻找它作为 Azure 容器实例或在 Azure 中以无服务器方式运行。

You can use kubernetes job .您可以使用kubernetes 作业

A Job creates one or more Pods and ensures that a specified number of them successfully terminate. Job 创建一个或多个 Pod 并确保指定数量的 Pod 成功终止。 As pods successfully complete, the Job tracks the successful completions.当 pod 成功完成时,作业会跟踪成功完成。 When a specified number of successful completions is reached, the task (ie, Job) is complete.当达到指定的成功完成次数时,任务(即 Job)就完成了。 Deleting a Job will clean up the Pods it created.删除作业将清理它创建的 Pod。

A simple case is to create one Job object in order to reliably run one Pod to completion.一个简单的案例是创建一个 Job object 以便可靠地运行一个 Pod 完成。 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).如果第一个 Pod 失败或被删除(例如由于节点硬件故障或节点重启),Job object 将启动一个新 Pod。

You can also use a Job to run multiple Pods in parallel.您还可以使用 Job 并行运行多个 Pod。

Here is an example Job config.这是一个示例作业配置。 It computes π to 2000 places and prints it out.它计算 π 到 2000 个位置并打印出来。 It takes around 10s to complete.大约需要 10 秒才能完成。

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如果要按重复计划运行批处理作业,请使用kubernetes cronjob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM