Skip to content

Kubernetes 部署

gocron 提供 Helm Chart,支持一键部署到 Kubernetes 集群。

前置要求

  • Kubernetes 1.19+
  • Helm 3.0+

安装

添加 Helm 仓库

bash
helm repo add gocron https://gocronx-team.github.io/gocron
helm repo update

快速安装

bash
# 默认使用 SQLite,最简配置
helm install gocron gocron/gocron

使用自定义配置

bash
# 方式一:命令行参数
helm install gocron gocron/gocron \
  --set db.engine=mysql \
  --set db.host=mysql.default \
  --set db.port=3306 \
  --set db.user=gocron \
  --set db.password=your_password \
  --set db.database=gocron

# 方式二:values 文件
helm install gocron gocron/gocron -f my-values.yaml

升级

bash
helm upgrade gocron gocron/gocron --set image.tag=1.5.9

卸载

bash
helm uninstall gocron

配置项

镜像

参数说明默认值
image.repository镜像地址gocronx/gocron
image.tag镜像标签Chart appVersion
image.pullPolicy拉取策略IfNotPresent

数据库

参数说明默认值
db.engine数据库类型:sqlitemysqlpostgressqlite
db.host数据库地址""
db.port数据库端口0
db.user数据库用户""
db.password数据库密码""
db.database数据库名称/SQLite 文件路径./data/gocron.db
db.prefix表前缀""
db.charset字符集utf8
db.maxIdleConns最大空闲连接数5
db.maxOpenConns最大连接数100

应用

参数说明默认值
app.name应用名称gocron
app.apiKeyAPI Key""
app.apiSecretAPI Secret""
app.allowIps允许访问的 IP""
app.concurrencyQueue并发队列大小500
app.enableTls启用 TLSfalse
timezone时区Asia/Shanghai

服务

参数说明默认值
service.type服务类型ClusterIP
service.port服务端口5920

Ingress

参数说明默认值
ingress.enabled启用 Ingressfalse
ingress.classNameIngress Class""
ingress.annotations注解{}
ingress.hosts主机配置[{host: gocron.local, paths: [{path: /, pathType: Prefix}]}]
ingress.tlsTLS 配置[]

持久化

参数说明默认值
persistence.enabled启用持久化true
persistence.storageClass存储类""
persistence.accessMode访问模式ReadWriteOnce
persistence.size存储大小1Gi

资源

参数说明默认值
resources.limits.cpuCPU 限制不限制
resources.limits.memory内存限制不限制
resources.requests.cpuCPU 请求不限制
resources.requests.memory内存请求不限制
replicaCount副本数1

注意

使用 SQLite 时副本数必须为 1,因为 SQLite 不支持多进程并发写入。使用 MySQL 或 PostgreSQL 可设置多副本。

部署示例

SQLite + NodePort

yaml
# values-sqlite.yaml
db:
  engine: sqlite

service:
  type: NodePort

persistence:
  enabled: true
  size: 2Gi

MySQL + Ingress

yaml
# values-mysql.yaml
db:
  engine: mysql
  host: mysql.database.svc
  port: 3306
  user: gocron
  password: your_password
  database: gocron

persistence:
  enabled: false

ingress:
  enabled: true
  className: nginx
  hosts:
    - host: gocron.example.com
      paths:
        - path: /
          pathType: Prefix
  tls:
    - secretName: gocron-tls
      hosts:
        - gocron.example.com

resources:
  requests:
    cpu: 100m
    memory: 128Mi
  limits:
    cpu: 500m
    memory: 256Mi

PostgreSQL + 多副本

yaml
# values-postgres.yaml
replicaCount: 3

db:
  engine: postgres
  host: pg.database.svc
  port: 5432
  user: gocron
  password: your_password
  database: gocron

persistence:
  enabled: false

注意事项

  1. SQLite 模式:Deployment 策略自动设为 Recreate(而非 RollingUpdate),避免多 Pod 同时访问 SQLite 文件
  2. 配置变更:修改 ConfigMap 后 Pod 会自动重启(通过 checksum annotation 实现)
  3. 数据持久化:SQLite 模式下务必启用 PVC,否则 Pod 重启后数据丢失
  4. 健康检查:默认配置了 liveness 和 readiness 探针,通过 HTTP 检查 5920 端口