目录
3.0、创建MySQL的xxl-job数据库,导入SQL脚本
3.2、xxl-job-admin的config-map.yaml
3.3、xxl-job-admin的deployment.yaml
3.4、xxl-job-admin的service.yaml
4.1、Dockerfile:xxl-job-executor-sample-springboot
4.2、部署xxl-job-executor-sample-springboot的pod
4.3、部署xxl-job-executor-sample-springboot的服务
xxl-job-executor-sample-springboot启动日志
Kubernetes | v1.21.5 |
kubesphere | v3.2.1 |
xxl-job | v2.3.1 |
mysql | 5.7 |
xxl-job官网 | 分布式任务调度平台XXL-JOB (xuxueli.com) |
- FROM java:8
- MAINTAINER demo
- RUN mkdir -p /app/config/
- ENV MYPATH /app
- WORKDIR $MYPATH
- ENV PARAMS="--spring.config.location=file:/app/config/application.properties"
- ENV TZ=PRC
- RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
- ADD target/xxl-job-admin-*.jar app.jar
- EXPOSE 8080
- EXPOSE 6666
- EXPOSE 9999
- ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6666 app.jar $PARAMS"]
- docker build -t zhxl1989/xxl-job:2.3.1 .
- docker push zhxl1989/xxl-job:2.3.1
- apiVersion: v1
- kind: ServiceAccount
- metadata:
- name: xxl-job
- namespace: default
- ---
- apiVersion: rbac.authorization.k8s.io/v1
- kind: RoleBinding
- metadata:
- name: xxl-job
- namespace: default
- roleRef:
- apiGroup: rbac.authorization.k8s.io
- kind: Role
- name: xxl-job
- subjects:
- - kind: ServiceAccount
- name: xxl-job
- namespace: default
- ---
- kind: Role
- apiVersion: rbac.authorization.k8s.io/v1
- metadata:
- namespace: default
- name: xxl-job
- rules:
- - apiGroups: [""]
- resources: ["pods"]
- verbs: ["get", "watch", "list"]
- apiVersion: v1
- kind: ConfigMap
- metadata:
- name: xxl-job-config
- namespace: default
- data:
- application.properties: |
- ### web
- server.port=${server.port}
- server.servlet.context-path=${server.servlet.context-path}
-
- ### actuator
- management.server.servlet.context-path=/actuator
- management.health.mail.enabled=false
-
- ### resources
- spring.mvc.servlet.load-on-startup=0
- spring.mvc.static-path-pattern=/static/**
- spring.resources.static-locations=classpath:/static/
-
- ### freemarker
- spring.freemarker.templateLoaderPath=classpath:/templates/
- spring.freemarker.suffix=.ftl
- spring.freemarker.charset=UTF-8
- spring.freemarker.request-context-attribute=request
- spring.freemarker.settings.number_format=0.##########
-
- ### mybatis
- mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
- #mybatis.type-aliases-package=com.xxl.job.admin.core.model
-
- ### xxl-job, datasource
- spring.datasource.url=${datasource.url}
- spring.datasource.username=${datasource.username}
- spring.datasource.password=${datasource.password}
- spring.datasource.driver-class-name=${datasource.driver.class.name}
-
- ### datasource-pool
- spring.datasource.type=com.zaxxer.hikari.HikariDataSource
- spring.datasource.hikari.minimum-idle=10
- spring.datasource.hikari.maximum-pool-size=30
- spring.datasource.hikari.auto-commit=true
- spring.datasource.hikari.idle-timeout=30000
- spring.datasource.hikari.pool-name=HikariCP
- spring.datasource.hikari.max-lifetime=900000
- spring.datasource.hikari.connection-timeout=10000
- spring.datasource.hikari.connection-test-query=SELECT 1
- spring.datasource.hikari.validation-timeout=1000
-
- ### xxl-job, email
- spring.mail.host=${mail.host}
- spring.mail.port=${mail.port}
- spring.mail.username=${mail.username}
- spring.mail.from=${mail.username}
- spring.mail.password=${mail.password}
- spring.mail.properties.mail.smtp.auth=${mail.properties.mail.smtp.auth}
- spring.mail.properties.mail.smtp.starttls.enable=${mail.properties.mail.smtp.starttls.enable}
- spring.mail.properties.mail.smtp.starttls.required=${mail.properties.mail.smtp.starttls.required}
- spring.mail.properties.mail.smtp.socketFactory.class=${mail.properties.mail.smtp.socketFactory.class}
-
- ### xxl-job, access token
- xxl.job.accessToken=default_token
-
- ### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
- xxl.job.i18n=${i18n}
-
- ## xxl-job, triggerpool max size
- xxl.job.triggerpool.fast.max=${fast}
- xxl.job.triggerpool.slow.max=${slow}
-
- ### xxl-job, log retention days
- xxl.job.logretentiondays=${logretentiondays}
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- name: xxl-job
- namespace: default
- spec:
- replicas: 1
- selector:
- matchLabels:
- app: xxl-job
- strategy:
- type: RollingUpdate
- rollingUpdate:
- maxUnavailable: 25%
- maxSurge: 25%
- revisionHistoryLimit: 10
- progressDeadlineSeconds: 600
- template:
- metadata:
- labels:
- app: xxl-job
- release: default
- spec:
- restartPolicy: Always
- terminationGracePeriodSeconds: 30
- dnsPolicy: ClusterFirst
- serviceAccountName: xxl-job
- serviceAccount: xxl-job
- securityContext: {}
- schedulerName: default-scheduler
- containers:
- - name: xxl-job
- image: zhxl1989/xxl-job:2.3.1
- imagePullPolicy: Always
- ports:
- - containerPort: 8080
- name: http
- - containerPort: 6666
- name: transport
- - containerPort: 9999
- name: executor
- resources:
- limits:
- cpu: '1'
- memory: 2Gi
- #nvidia.com/gpu: 4k
- requests:
- cpu: 500m
- memory: 1Gi
- #nvidia.com/gpu: 4k
- env:
- - name: server.port
- value: "8080"
- - name: server.servlet.context-path
- value: "/xxl-job-admin"
- - name: datasource.url
- value: "jdbc:mysql://mysql.shenyu.svc.cluster.local:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai"
- - name: datasource.username
- value: "root"
- - name: datasource.password
- value: "123456"
- - name: datasource.driver.class.name
- value: "com.mysql.cj.jdbc.Driver"
- - name: mail.host
- value: "smtp.qq.com"
- - name: mail.port
- value: "25"
- - name: mail.username
- value: "1024122298@qq.com"
- - name: mail.password
- value: "thomsesuwwfcf19jcnwrddi"
- - name: mail.properties.mail.smtp.auth
- value: "true"
- - name: mail.properties.mail.smtp.starttls.enable
- value: "true"
- - name: mail.properties.mail.smtp.starttls.required
- value: "true"
- - name: mail.properties.mail.smtp.socketFactory.class
- value: "javax.net.ssl.SSLSocketFactory"
- - name: i18n
- value: "zh_CN"
- - name: fast
- value: "200"
- - name: slow
- value: "100"
- - name: logretentiondays
- value: "30"
- - name: real_host
- valueFrom:
- fieldRef:
- fieldPath: status.podIP
- volumeMounts:
- - mountPath: /etc/localtime
- name: volume-localtime
- - name: config
- mountPath: /app/config/application.properties
- #对应面下面的path,保持一致
- subPath: application.properties
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- volumes:
- - hostPath:
- path: /etc/localtime
- type: ''
- name: volume-localtime
- - name: config
- configMap:
- #对应config-map的名称
- name: xxl-job-config
- items:
- - key: application.properties
- #对应上面的subPath,保持一致
- path: application.properties
- apiVersion: v1
- kind: Service
- metadata:
- name: xxl-job
- namespace: default
- labels:
- service: xxl-job
- spec:
- sessionAffinity: "ClientIP"
- ports:
- - name: transport
- port: 6666
- protocol: TCP
- targetPort: 6666
- nodePort: 30666
- - name: http
- port: 8080
- protocol: TCP
- targetPort: 8080
- nodePort: 30888
- - name: executor
- port: 9999
- protocol: TCP
- targetPort: 9999
- nodePort: 31999
- selector:
- app: xxl-job
- type: NodePort
- FROM java:8
- MAINTAINER demo
- RUN mkdir -p /data/applogs/xxl-job/jobhandler
- ENV MYPATH /
- WORKDIR $MYPATH
- 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
- EXPOSE 8081
- EXPOSE 9999
- ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]
- docker build -t zhxl1989/xxl-job-executor-sample-springboot:2.3.1 .
- docker push zhxl1989/xxl-job-executor-sample-springboot:2.3.1
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- name: xxl-job-executor-sample-springboot
- namespace: default
- spec:
- replicas: 1
- selector:
- matchLabels:
- app: xxl-job-executor-sample-springboot
- strategy:
- type: RollingUpdate
- rollingUpdate:
- maxUnavailable: 25%
- maxSurge: 25%
- revisionHistoryLimit: 10
- progressDeadlineSeconds: 600
- template:
- metadata:
- labels:
- app: xxl-job-executor-sample-springboot
- release: default
- spec:
- restartPolicy: Always
- containers:
- - name: xxl-job-executor-sample-springboot
- image: zhxl1989/xxl-job-executor-sample-springboot:2.3.1
- imagePullPolicy: Always
- ports:
- - containerPort: 8081
- name: http
- - containerPort: 9999
- name: executor
- resources:
- limits:
- cpu: '1'
- memory: 2Gi
- requests:
- cpu: 500m
- memory: 1Gi
- volumeMounts:
- - mountPath: /etc/localtime
- name: volume-localtime
- volumes:
- - hostPath:
- path: /etc/localtime
- type: ''
- name: volume-localtime
- apiVersion: v1
- kind: Service
- metadata:
- name: xxl-job-executor-sample-springboot
- namespace: default
- labels:
- service: xxl-job-executor-sample-springboot
- spec:
- ports:
- - name: executor
- port: 9999
- protocol: TCP
- targetPort: 9999
- nodePort: 30999
- - name: http
- port: 8081
- protocol: TCP
- targetPort: 8081
- nodePort: 30881
- selector:
- app: xxl-job-executor-sample-springboot
- type: NodePort
AppName为POD(xxl-job-executor-sample-springboot-54dfccf96b-8th69)的应用名称,名称自定义。
在表xxl_job_registry和xxl_job_group中可以看到添加的内容
在右侧“操作”中选择GLUE IDE编辑内容,编辑后保存,每两分钟执行定时任务。
- docker stop test && docker rm test
- docker images | grep zhxl1989 | awk '{print $3}' | xargs docker rmi
- docker build -t zhxl1989/xxl-job:2.3.1 .
- docker push zhxl1989/xxl-job:2.3.1
-
- kubectl describe pod xxl-job
-
-
- docker stop test && docker rm test
- docker run -itd --privileged=true --name test -p 8080:8080 -v /home/deploy/:/app/config/ --restart unless-stopped zhxl1989/xxl-job:2.3.1
- docker logs -f test
-
- kubectl exec -it dnsutils nslookup kubernetes.default
-
-
-
- kubectl exec -it dnsutils -- cat /etc/resolv.conf
-
- kubectl get pods --namespace=kube-system -l k8s-app=kube-dns
-
-
- kubectl get endpoints coredns --namespace=kube-system
-
-
- kubectl describe svc coredns --namespace=kube-system
-
-
- kubectl -n kube-system edit configmap coredns
-
-
- kubectl logs -f --namespace=kube-system -l k8s-app=kube-dns
-
-
-
- kubectl get svc kube-dns -n kube-system
- kubectl get deployment coredns -n kube-system
-
-
-
-