https://github.com/teslacn/elasticjob-kubernetes
A new ElasticJob Cloud on Kubernetes
https://github.com/teslacn/elasticjob-kubernetes
distributed-schedule-system distributed-scheduling elasticjob kubernetes kubernetes-operator schedule scheduler scheduling
Last synced: about 1 month ago
JSON representation
A new ElasticJob Cloud on Kubernetes
- Host: GitHub
- URL: https://github.com/teslacn/elasticjob-kubernetes
- Owner: TeslaCN
- Created: 2023-01-29T01:30:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-16T08:22:06.000Z (over 3 years ago)
- Last Synced: 2025-02-01T18:44:14.761Z (over 1 year ago)
- Topics: distributed-schedule-system, distributed-scheduling, elasticjob, kubernetes, kubernetes-operator, schedule, scheduler, scheduling
- Language: Java
- Homepage:
- Size: 73.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
= ElasticJob on Kubernetes
== Getting Started
=== Implements Your ElasticJob
[source,java]
....
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
public class MyLogSimpleJob implements SimpleJob {
@Override
public void execute(final ShardingContext shardingContext) {
// Do what you want.
}
}
....
=== Launch Your Job using ElasticJob-Cloud API
[source,java]
....
import icu.wwj.elasticjob.example.job.MyLogSimpleJob;
import org.apache.shardingsphere.elasticjob.cloud.api.JobBootstrap;
public class Main {
public static void main(String[] args) {
JobBootstrap.execute(new MyLogSimpleJob());
}
}
....
=== Build Image and Make Image Ready in Image Registry
See example.
=== Deploy ElasticJob Operator
TODO
=== Create ElasticJob CR
See example.
[source,bash]
....
kubectl apply -f https://raw.githubusercontent.com/TeslaCN/elasticjob-kubernetes/main/example/k8s/transient/elasticjob.yaml
....
[source,yaml]
....
apiVersion: icu.wwj.elasticjob/v1alpha1
kind: ElasticJob
metadata:
name: hello-transient-job
namespace: elasticjob-cloud
spec:
template:
metadata:
labels:
app: elasticjob
spec:
restartPolicy: OnFailure
containers:
- name: job-container
imagePullPolicy: IfNotPresent
image: teslacn/elasticjob-kubernetes-example:latest
jobExecutionType: TRANSIENT
shardingTotalCount: 3
shardingItemParameters:
1: a
2: b
0: c
jobParameter: 'common parameter'
# Transient job only support minute level cron. The second expression would be ignored.
cron: '0 * * * * ?'
misfire: true
description: ''
props:
a: b
disabled: false
....
=== Scale Job via kubectl
[source,bash]
....
kubectl scale --replicas=5 -n elasticjob-cloud elasticjob/hello-transient-job
....
== Basic Concept
*ElasticJob on Kubernetes* vs *ElasticJob Cloud 3.0 (Mesos)*
|===
| ElasticJob concept | ElasticJob Kubernetes | ElasticJob Mesos
| API | CRD elasticjobs.icu.wwj.elasticjob | Restful API
| Scheduler | ElasticJob Operator | base on Mesos Scheduler & Executor
| Application | An Image | A Tarball
|===
Kubernetes resource:
|===
| Job Execution Type | DAEMON | TRANSIENT
| ElasticJob with CRON | ✅ StatefulSet | ✅ CronJob
| ElasticJob without CRON | ❌ StatefulSet | ✅ Job
|===
* ✅ means supported
* ❌ means unsupported for now
== Limitations
[.lead]
Transient cron job (Kubernetes CronJob) only support UNIX cron. The second expression would be ignored.
For example, set the following cron in ElasticJob CR:
[source,yaml]
....
jobExecutionType: TRANSIENT
cron: '0/15 * * * * ?'
....
The actual cron of CronJob would be:
....
* * * * ?
....