Kubernetes job
Install the SchedulerX agent in a Kubernetes environment to schedule native Kubernetes Pods and Jobs. SchedulerX provides status monitoring, alerting, log collection, and diagnostics for your jobs.
How it works
The following diagram shows how SchedulerX schedules a Kubernetes job:

The following table compares Kubernetes jobs and script jobs.
|
Scenario |
Script job |
Kubernetes job |
|
Infrequent execution with high resource consumption. |
Not recommended. Forking a child process for each run consumes resources on the agent's machine and can overload the system. |
Recommended. Kubernetes uses its load balancing strategy to launch a new Pod for each run, ensuring high stability. |
|
Frequent execution with low resource consumption. |
Recommended. Forking a child process is fast and resource-efficient. |
Not recommended. Pulling an image and starting a Pod for each run is slow. Frequent API server calls to schedule Pods or Jobs can lead to rate limiting. |
|
How to build dependencies. |
Manually deploy dependencies to ECS instances in advance. |
Build dependencies into a base image. You must rebuild the base image if dependencies change. |
Prerequisites
Connect to SchedulerX. For more information, see Deploy SchedulerX in a Kubernetes cluster.
Create a Kubernetes job
Shell script
To run a shell script in a Pod without building your own image, create a Kubernetes job on the Tasks page and select Shell-Script as the resource type. The default image is BusyBox, which you can replace with your own.
Example configuration: Set Task type to K8s and resource type to Shell-Script. The default Image is BusyBox. Enter your shell script content, such as echo hello schedulerx, in the script editor.
Click Run once. A Pod named schedulerx-shell-{JobId} starts in the Kubernetes cluster.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
schedulerx-shell-xxx 1/1 Running 0 xxx
On the Task Management page in the SchedulerX console, you can view the execution history and Pod logs. The log output area displays the script's result, such as hello schedulerx, along with the execution time and status.
Python script
To run a Python script in a Pod without building your own image, create a Kubernetes job on the Tasks page and select Python-Script as the resource type. The default image is python, which you can replace with your own.
Example configuration: Set Task type to K8s and resource type to Python-Script. The default Image is python. Enter your Python script content, such as print('hello schedulerx'), in the script editor.
Click Run once. A Pod named schedulerx-python-{JobId} starts in the Kubernetes cluster.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
schedulerx-python-xxx 1/1 Running 0 xxx
On the Task Management page in the SchedulerX console, you can view the execution history and Pod logs. The procedure is the same as for shell scripts. The log output area displays the script's result.
PHP script
To run a PHP script in a Pod without building your own image, create a Kubernetes job on the Tasks page and select Php-Script as the resource type. The default image is php:7.4-cli, which you can replace with your own.
Example configuration: Set Task type to K8s and resource type to Php-Script. The default Image is php:7.4-cli. Enter your PHP script content in the script editor.
Click Run once. A Pod named schedulerx-php-{JobId} starts in the Kubernetes cluster.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
schedulerx-php-xxx 1/1 Running 0 xxx
On the Task Management page in the SchedulerX console, you can view the execution history and Pod logs. The procedure is the same as for shell scripts. The log output area displays the script's result.
Node.js script
To run a Node.js script in a Pod without building your own image, create a Kubernetes job on the Tasks page and select Node.js-Script as the resource type. The default image is node:16, which you can replace with your own.
Example configuration: Set Task type to K8s and resource type to Node.js-Script. The default Image is node:16. Enter your Node.js script content, such as console.log('hello schedulerx'), in the script editor.
Click Run once. A Pod named schedulerx-node-{JobId} starts in the Kubernetes cluster.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
schedulerx-node-xxx 1/1 Running 0 xxx
On the Task Management page in the SchedulerX console, you can view the execution history and Pod logs. The procedure is the same as for shell scripts. The log output area displays the script's result.
Job-YAML
You can also use SchedulerX to run a native Kubernetes Job. Set the task type to K8s and the resource type to Job-YAML.
Example configuration: Set Task type to K8s and resource type to Job-YAML. Enter the standard Kubernetes Job definition in the YAML editor, including fields such as apiVersion, kind, metadata, and spec.
Click Run once. The Job and its associated Pod start in the Kubernetes cluster.
$ kubectl get jobs
NAME COMPLETIONS DURATION AGE
schedulerx-xxx 1/1 xxx xxx
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
schedulerx-xxx 0/1 Completed 0 xxx
On the Task Management page in the SchedulerX console, you can view the execution history and Pod logs. The log output area displays the Job's result, execution time, and status.
When running a Kubernetes Job with SchedulerX, we recommend against using a CronJob. Instead, configure the schedule in SchedulerX to ensure that it collects the execution history and logs for each Pod.
Pod-YAML
You can also use SchedulerX to run a native Kubernetes Pod. Set the task type to K8s and the resource type to Pod-YAML.
Example configuration: Set Task type to K8s and resource type to Pod-YAML. Enter the standard Kubernetes Pod definition in the YAML editor, including fields such as apiVersion, kind, metadata, and spec.
Click Run once. The Pod starts in the Kubernetes cluster.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
schedulerx-xxx 1/1 Running 0 xxx
On the Task Management page in the SchedulerX console, you can view the execution history and Pod logs. The log output area displays the Pod's result, execution time, and status.
When you use SchedulerX to run a Kubernetes Pod, we recommend that you do not run long-lived Pods, such as those for web applications that never terminate. You must set the restart policy to Never. Otherwise, the Pod will restart continuously.
Job parameters from environment variables
SchedulerX injects job parameters as environment variables. Scripts, Pods, and Jobs can read these parameters directly from the environment.
This feature requires SchedulerX agent version 1.10.14 or later.
|
Parameter |
Description |
|
SCHEDULERX_JOB_NAME |
The name of the job. |
|
SCHEDULERX_SCHEDULE_TIMESTAMP |
The job's scheduling timestamp. |
|
SCHEDULERX_DATA_TIMESTAMP |
The data timestamp for the job. |
|
SCHEDULERX_WORKFLOW_INSTANCE_ID |
The ID of the workflow instance, if the job is part of a workflow. |
|
SCHEDULERX_JOB_PARAMETERS |
The job parameters. |
|
SCHEDULERX_INSTANCE_PARAMETERS |
The instance parameters of the job. |
|
SCHEDULERX_JOB_SHARDING_PARAMETER |
The sharding parameters, if the job is a sharded job. |
The following example shows how to retrieve a SchedulerX job parameter:
Example: Enter a value in the Job Parameters field in the job configuration. In your script, you can then read the SCHEDULERX_JOB_PARAMETERS environment variable to access this value. For example, a shell script can use echo $SCHEDULERX_JOB_PARAMETERS to print the parameter.
Advantages
Scheduling a Kubernetes Job with SchedulerX offers the following advantages over native Kubernetes Jobs:
Online script editing
A common use case for a Kubernetes Job is data processing or operations tasks, often implemented as scripts. The native workflow requires you to package the script into an image and configure the command in a YAML file. Each script change requires rebuilding and redeploying the image. For example:
apiVersion: batch/v1
kind: Job
metadata:
name: hello
spec:
template:
spec:
containers:
- name: hello
image: busybox
command: ["sh", "/root/hello.sh"]
restartPolicy: Never
backoffLimit: 4
With SchedulerX, you do not need to build images or write YAML to configure scripts. You can edit scripts for Shell, Python, PHP, and Node.js directly in the console, and the system automatically runs them in a Pod. To update a script, edit and save it in the console. The updated script runs at the next scheduled time. This significantly improves the efficiency of developing and managing Kubernetes Jobs. By abstracting away container-related details, SchedulerX also makes it easier for developers who are not familiar with container services to work with Kubernetes.
For example:
On the job editing page in the SchedulerX console, you can write and modify script content directly in the script editor. After you finish, click Save. The latest version of the script will automatically run at the next scheduled time.
Visual job orchestration
In the Kubernetes ecosystem, Argo is a popular solution for workflow orchestration. For example:
# The following workflow executes a diamond workflow
#
# A
# / \
# B C
# \ /
# D
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-diamond-
spec:
entrypoint: diamond
templates:
- name: diamond
dag:
tasks:
- name: A
template: echo
arguments:
parameters: [{name: message, value: A}]
- name: B
depends: "A"
template: echo
arguments:
parameters: [{name: message, value: B}]
- name: C
depends: "A"
template: echo
arguments:
parameters: [{name: message, value: C}]
- name: D
depends: "B && C"
template: echo
arguments:
parameters: [{name: message, value: D}]
- name: echo
inputs:
parameters:
- name: message
container:
image: alpine:3.7
command: [echo, "{{inputs.parameters.message}}"]
SchedulerX lets you visually orchestrate Kubernetes Jobs by using a drag-and-drop interface.
Compared to Argo, SchedulerX provides a more user-friendly experience. During runtime, it displays a visual workflow graph that tracks job progress, making it easy to identify bottlenecks or failed tasks.
In the workflow instance view, each task node is color-coded by its status (for example, green for success and red for failure), allowing you to visually pinpoint the failure.
Monitoring and alerting
When you schedule Pods and Jobs with SchedulerX, you can use its built-in monitoring and alerting system for status tracking and exception alerting.
-
Supported alert channels: SMS, phone call, email, and webhook (for DingTalk, WeCom, and Lark).
-
Supported alert policies: alert on failure and alert on execution timeout.
Log service
When you use SchedulerX to schedule Pods and Jobs, the system automatically collects logs generated during Pod execution. You do not need to enable an additional log service. If a Pod fails, you can view and analyze the failure reason in the SchedulerX console for quick troubleshooting.
In the task instance details, you can view the complete logs generated during Pod execution, including stack traces and failure reasons, to help you quickly identify and debug issues.
Monitoring dashboard
By using SchedulerX to schedule Pods and Jobs, you can access the built-in job monitoring dashboard without needing to set up a service like Prometheus.
The monitoring dashboard displays key metrics such as job execution counts, success and failure rates, and execution duration trends, providing a global view of your jobs' operational status.
Mixed job deployment
For online jobs that require high real-time performance, such as order processing, you can invoke methods directly within the same process for efficient handling and seamless integration with online services. For offline jobs that have lower real-time requirements but consume significant resources, such as scheduled report exports, you can write a script and run it in a separate Pod. SchedulerX supports both Java and Kubernetes job types, allowing you to implement a mixed deployment of online and offline jobs.