Kubernetes v1.21.5部署xxl-job 2.3.1

目录

1、软件版本

2、制作xxl-job-admin的docker镜像

           Dockerfile:

           执行命令:

3、部署xxl-job

3.0、创建MySQL的xxl-job数据库,导入SQL脚本

3.1、xxl-job-admin的rabc.yaml

3.2、xxl-job-admin的config-map.yaml

3.3、xxl-job-admin的deployment.yaml

3.4、xxl-job-admin的service.yaml

3.5、容器启动日志

3.6、访问xxl-job-admin

4、部署executor执行器

 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启动日志

 4.4、xxl-job-admin页面新建执行器

自定义添加执行器在数据库的保存

等待一会儿,自动注册方式,Online的机器地址会显示出来 

5、执行测试

5.1、任务管理新建任务

5.2、运行模式GLUE(Java),编辑内容

5.3、在容器中查看运行日志

5.4、xxl-job-admin调度日志

附录:


1、软件版本

Kubernetesv1.21.5
kubespherev3.2.1
xxl-jobv2.3.1
mysql5.7
xxl-job官网
 
分布式任务调度平台XXL-JOB (xuxueli.com)

2、制作xxl-job-admin的docker镜像

Dockerfile:

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

3、部署xxl-job

3.0、创建MySQL的xxl-job数据库,导入SQL脚本

3.1、xxl-job-admin的rabc.yaml

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"]

3.2、xxl-job-admin的config-map.yaml

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}

3.3、xxl-job-admin的deployment.yaml

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

3.4、xxl-job-admin的service.yaml

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

3.5、容器启动日志

3.6、访问xxl-job-admin

任务调度中心

4、部署executor执行器

4.1、Dockerfile:xxl-job-executor-sample-springboot

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

4.2、部署xxl-job-executor-sample-springboot的pod

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

4.3、部署xxl-job-executor-sample-springboot的服务

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

xxl-job-executor-sample-springboot启动日志

4.4、xxl-job-admin页面新建执行器

AppName为POD(xxl-job-executor-sample-springboot-54dfccf96b-8th69)的应用名称,名称自定义。

自定义添加执行器在数据库的保存

在表xxl_job_registry和xxl_job_group中可以看到添加的内容

等待一会儿,自动注册方式,Online的机器地址会显示出来 

5、执行测试

5.1、任务管理新建任务

5.2、运行模式GLUE(Java),编辑内容

在右侧“操作”中选择GLUE IDE编辑内容,编辑后保存,每两分钟执行定时任务。

 5.3、在容器中查看运行日志

5.4、xxl-job-admin调度日志

附录:

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




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值