How do I schedule recurring jobs in Argo with CronWorkflow and WorkflowTemplates?
In this guide, we will create a recurring job in Argo using CronWorkflow and WorkflowTemplates. Argo Workflows is an open-source container-native workflow engine for orchestrating parallel jobs on Kubernetes. We will define a WorkflowTemplate and a CronWorkflow to schedule the recurring job.
The WorkflowTemplate defines the sequence of steps to be executed, and the CronWorkflow schedules the execution of the WorkflowTemplate at specified intervals.
Below is the Pulumi program in TypeScript to set up a CronWorkflow and WorkflowTemplate in Argo.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
// Define the WorkflowTemplate
const workflowTemplate = new k8s.apiextensions.CustomResource("workflowTemplate", {
apiVersion: "argoproj.io/v1alpha1",
kind: "WorkflowTemplate",
metadata: { name: "hello-world-template" },
spec: {
entrypoint: "whalesay",
templates: [{
name: "whalesay",
container: {
image: "docker/whalesay",
command: ["cowsay"],
args: ["hello world"],
},
}],
},
});
// Define the CronWorkflow
const cronWorkflow = new k8s.apiextensions.CustomResource("cronWorkflow", {
apiVersion: "argoproj.io/v1alpha1",
kind: "CronWorkflow",
metadata: { name: "hello-world-cron" },
spec: {
schedule: "0 0 * * *", // Daily at midnight
workflowSpec: {
entrypoint: "whalesay",
templates: [{
name: "whalesay",
container: {
image: "docker/whalesay",
command: ["cowsay"],
args: ["hello world"],
},
}],
},
},
});
// Export the names of the created resources
export const workflowTemplateName = workflowTemplate.metadata.name;
export const cronWorkflowName = cronWorkflow.metadata.name;
Key Points
- WorkflowTemplate: Defines the sequence of steps to be executed in the workflow. In this example, it runs a Docker container that outputs “hello world”.
- CronWorkflow: Schedules the execution of the WorkflowTemplate at specified intervals. In this example, it runs daily at midnight.
Summary
In this guide, we created a recurring job in Argo using CronWorkflow and WorkflowTemplates with Pulumi. The WorkflowTemplate defines the task to be executed, and the CronWorkflow schedules it to run at a specified interval. This setup allows you to automate and schedule tasks efficiently in a Kubernetes environment.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.