Openshift或者K8S上部署xxl-job
本案例以版本2.3.0为例
1. 源码编译成jar包
source code:
https://github.com/xuxueli/xxl-job/blob/2.3.0/
这里我们会得到两个jar包:xxl-job-admin-2.3.0.jar和xxl-job-executor-sample-springboot-2.3.0.jar
2. 初始化mysql数据库
sql code:
https://github.com/xuxueli/xxl-job/blob/2.3.0/doc/db/tables_xxl_job.sql
3. 构建镜像
xxl-job-admin参考:
https://github.com/xuxueli/xxl-job/blob/2.3.0/xxl-job-admin/Dockerfile
FROM openjdk:8-jre-slim
MAINTAINER xuxueli
ENV PARAMS=""
ENV TZ=PRC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD target/xxl-job-admin-*.jar /app.jar
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]
xxl-job-executor-sample-springboot参考:
https://github.com/xuxueli/xxl-job/blob/2.3.0/xxl-job-executor-samples/xxl-job-executor-sample-springboot/Dockerfile
FROM openjdk:8-jre-slim
MAINTAINER xuxueli
ENV PARAMS=""
ENV TZ=PRC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD target/xxl-job-executor-sample-springboot-*.jar /app.jar
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]
build镜像后上传至自己的harbor镜像仓库。
4. 开始部署
job-admin的yaml部署文件:
kind: Deployment
apiVersion: apps/v1
metadata:
name: xxl-job
labels:
app.kubernetes.io/instance: xxl-job
spec:
replicas: 1
selector:
matchLabels:
app: xxl-job
template:
metadata:
labels:
app: xxl-job
deployment: xxl-job
spec:
containers:
- resources:
limits:
cpu: '1'
memory: 4Gi
requests:
cpu: 500m
memory: 4Gi
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 30
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
name: xxl-job
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 30
timeoutSeconds: 1
periodSeconds: 30
successThreshold: 1
failureThreshold: 3
env:
- name: PARAMS
value: '--spring.datasource.url=jdbc:mysql://xxx:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=xxx --spring.datasource.password=xxx' ###这里需要填写mysql的连接信息
ports:
- name: http
containerPort: 8080
protocol: TCP
image: xxl-job:v2.3.0 ### 自己build的镜像地址
restartPolicy: Always
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
revisionHistoryLimit: 1
---
kind: Service
apiVersion: v1
metadata:
name: xxl-job
spec:
ports:
- name: 8080-tcp
protocol: TCP
port: 8080
targetPort: 8080
type: ClusterIP
selector:
deployment: xxl-job
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: xxl-job
spec:
ingressClassName: openshift-default
rules:
- host: xxx ## 这边填写域名
http:
paths:
- path: /xxl-job-admin
pathType: Prefix
backend:
service:
name: xxl-job
port:
name: 8080-tcp
job-executor部署的yaml:
kind: Deployment
apiVersion: apps/v1
metadata:
name: xxl-job-executor
spec:
replicas: 1
selector:
matchLabels:
app: xxl-job-executor
template:
metadata:
labels:
app: xxl-job-executor
deployment: xxl-job-executor
spec:
containers:
- name: xxl-job-executor
env:
- name: PARAMS
value: "--xxl.job.admin.addresses=https://xxx/xxl-job-admin --xxl.job.executor.port=9999"
## 这里需要指定上一步job-admin的地址,以及job-executor的端口
resources:
requests:
cpu: 500m
memory: 4Gi
limits:
cpu: 1000m
memory: 4Gi
image: xxl-job-executor:v2.3.0 ### 自己build的镜像地址
ports:
- name: http
containerPort: 8081
protocol: TCP
- name: executor-http
containerPort: 9999
protocol: TCP
readinessProbe:
tcpSocket:
port: 8081
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
livenessProbe:
tcpSocket:
port: 8081
initialDelaySeconds: 30
periodSeconds: 30
successThreshold: 1
failureThreshold: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
5. visit xxl-job web
初始的用户名密码
username: admin
password: 123456