kubernets搭建xxl-job
Dockerfile文件:
FROM openjdk:8-jre-slim
MAINTAINER wang.T
WORKDIR /app
ENV PARAMS=""
ENV TZ=PRC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD xxl-job-admin-*.jar ./app.jar
COPY application.yml ./
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS ./app.jar $PARAMS"]
application.yml
management:
health:
mail:
enabled: false
server:
servlet:
context-path: /actuator
mybatis:
mapper-locations: classpath:/mybatis-mapper/*Mapper.xml
server:
port: 8080
servlet:
context-path: /xxl-job-admin
spring:
ldap:
urls: ldap://ldap.idcsec.com:1389
base: ou=xxxx,dc=idcsec,dc=com
username: cn=admin,dc=idcsec,dc=com
password: xxx!
admin: xxx
repositories:
enabled: false
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
hikari:
auto-commit: true
connection-test-query: SELECT 1
connection-timeout: 10000
idle-timeout: 30000
max-lifetime: 900000
maximum-pool-size: 30
minimum-idle: 10
pool-name: HikariCP
validation-timeout: 1000
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
username: xxx
password: xxxx
freemarker:
charset: UTF-8
request-context-attribute: request
settings:
new_builtin_class_resolver: safer
number_format: 0.##########
suffix: .ftl
templateLoaderPath: classpath:/templates/
mail:
from: xxx@qq.com
host: smtp.qq.com
password: xxx
port: 25
properties:
mail:
smtp:
auth: true
socketFactory:
class: javax.net.ssl.SSLSocketFactory
starttls:
enable: true
required: true
username: xxx@qq.com
mvc:
servlet:
load-on-startup: 0
static-path-pattern: /static/**
resources:
static-locations: classpath:/static/
xxl:
job:
alarm:
wechat-robot-webhook:
accessToken: token
i18n: zh_CN
logretentiondays: 30
triggerpool:
fast:
max: 200
slow:
max: 100
这里主要配置accessToken 数据库配置不用管 会放在PARAMS 优先获取变量
Deployment文件:
PARAMS环境变量根据自己需要修改
xxl-job-prod.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: xxl-job-admin
labels:
app: xxl-job-admin
spec:
replicas: 1
selector:
matchLabels:
app: xxl-job-admin
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: xxl-job-admin
spec:
containers:
- name: xxl-job-admin
image: harbor.idcsec.com/base/xxl-job-admin:2.4.1
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: 1000m
memory: 4096Mi
requests:
cpu: 500m
memory: 1023Mi
env:
- name: JAVA_OPTS
value: "-Xmx2048m -Xms2048m"
- name: PARAMS
value: "--spring.datasource.url=jdbc:mysql://10.10.5.19:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=xxl_job --spring.datasource.password=123456 --spring.ldap.repositories.enabled=true --spring.ldap.admin=xxx --xxl.job.alarm.wechat-robot-webhook=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx"
ports:
- containerPort: 8080
volumeMounts:
- name: vol-log
mountPath: /data/applogs
livenessProbe:
httpGet:
path: /xxl-job-admin/actuator/health
port: 8080
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /xxl-job-admin/actuator/health
port: 8080
scheme: HTTP
initialDelaySeconds: 3
timeoutSeconds: 3
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
imagePullSecrets:
- name: registry-key
volumes:
- name: vol-log
hostPath:
path: /data/k8s/logs
---
apiVersion: v1
kind: Service
metadata:
name: xxl-job-admin
labels:
app: xxl-job-admin
spec:
ports:
- port: 8080
targetPort: 8080
name: web
selector:
app: xxl-job-admin
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: xxl-job-admin
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: xxljob-admin.idcsec.com
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: xxl-job-admin
port:
number: 8080
构建镜像推送仓库:
docker build -t harbor.idcsc.com/base/xxl-job-admin:2.4.1 .
docker push harbor.idcsc.com/base/xxl-job-admin:2.4.1