k8s部署xxl-job

环境

k8s版本:1.21
xxl-job的docker tag: 2.30.0
mysql:5.7

相关连接

文档:中文文档
github地址:项目地址
sql语句: sql语句

编写k8s部署文档

#这是最终成功部署xxl-job的yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
  labels: 
    app: xxl-job
  namespace: platform
  name: xxl-job
spec:
  replicas: 1
  selector:
    matchLabels:
      app: xxl-job
  template:
    metadata:
      labels:
        app: xxl-job
    spec:
      containers:
      - name: xxl-job
        image: xuxueli/xxl-job-admin:2.3.0
        env:
        - name: PARAMS
          value: '--spring.config.location=/data/applogs/xxl-job/config/application.properties'
        ports:
        - containerPort: 8080
          name: tcp8080
        - containerPort: 9999
          name: tcp9999
        volumeMounts:
        - mountPath: /data/applogs
          name: xxl-job-admin
          subPath: xxl-job/logs/
        - mountPath: /etc/localtime
          name: time
        - mountPath: /data/applogs/xxl-job/config/application.properties
          name: xxl-job-admin
          subPath: xxl-job/config/application.properties
      volumes:
      - hostPath: 
          path: /etc/localtime
        name: time
      - name: xxl-job-admin
        persistentVolumeClaim:
          claimName: platform-pvc
          
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: xxl-job
  name: xxl-job-nodeport
  namespace: platform
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
    nodePort: 30418
    name: tcp8080
  type: NodePort
  selector:
    app: xxl-job

注:按照官方给的docker部署文档,传递环境变量

  ...
  env:
  - name: PARAMS
    value: "--spring.datasource.url=jdbc:mysql://192.168.1.2:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=123456"

将外置mysql连接参数传递给pod,但是apply 过后,pod一直提示无法连接mysql,并且连接的是:'root'@'pod_ip'。这意味着我们传入的参数没生效。然后将pod内的配置文件挂载到外面使用,参看:上面yaml文件中volumeMounts字段中的xxl-job-admin配置。

注:需先在pvc的实际目录中创建xxl-job/config/application.properties,然后将配置文件写入到这个文件中,并修改mysql连接信息。如下application.properties:

### web
server.port=8080
server.servlet.context-path=/xxl-job-admin

### 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=jdbc:mysql://192.168.1.2:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

### 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=smtp.qq.com
spring.mail.port=25
spring.mail.username=xxx@qq.com
spring.mail.from=xxx@qq.com
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

### 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=zh_CN

## xxl-job, triggerpool max size
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100

### xxl-job, log retention days
xxl.job.logretentiondays=30

此时依然还是访问的pod自己的mysql。表示这一步还是没有生效。

解决

因为xxl-job在jar包中还有一个application.properties,所以需要指定使用本地的配置文件,修改yaml中传递的环境变量为:

...
        env:
        - name: PARAMS
          value: '--spring.config.location=/data/applogs/xxl-job/config/application.properties'
...

当然,这个前提是你需要将文件挂载出来。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值