Skip to content

Latest commit

 

History

History
127 lines (102 loc) · 2.7 KB

README.adoc

File metadata and controls

127 lines (102 loc) · 2.7 KB

ElasticJob on Kubernetes

Getting Started

Implements Your ElasticJob

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

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.

kubectl apply -f https://raw.githubusercontent.com/TeslaCN/elasticjob-kubernetes/main/example/k8s/transient/elasticjob.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

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

Transient cron job (Kubernetes CronJob) only support UNIX cron. The second expression would be ignored.

For example, set the following cron in ElasticJob CR:

  jobExecutionType: TRANSIENT
  cron: '0/15 * * * * ?'

The actual cron of CronJob would be:

* * * * ?