Kubernetes中通过Helm部署多副本Gitea失败求助
问题描述
通过Helm部署Gitea时,单实例运行正常,但将replicaCount设置为2后Pod无法启动,报错如下:
Error: INSTALLATION FAILED: template: gitea/templates/gitea/deployment.yaml:29:28: executing "gitea/templates/gitea/deployment.yaml" at <include (print $.Template.BasePath "/gitea/config.yaml") .>: error calling include: template: gitea/templates/gitea/config.yaml:28:40: executing "gitea/templates/gitea/config.yaml" at <"cron.GIT_GC_REPOS">: wrong type for value; expected map[string]interface {}; got string
使用的values.yaml配置:
replicaCount: 2 redis-cluster: enabled: false postgresql: enabled: false postgresql-ha: enabled: false persistence: enabled: true create: false mount: true claimName: cluster-nfs-pvc size: 10Gi accessModes: - ReadWriteMany labels: {} storageClass: subPath: annotations: helm.sh/resource-policy: keep gitea: admin: existingSecret: username: admin password: admin email: "admin@example.com" config: server: DOMAIN: gitea.qtest.example.com ROOT_URL: https://gitea.qtest.example.com SSH_LISTEN_PORT: 2222 database: DB_TYPE: postgres HOST: db.example.com:5432 NAME: gitea_db USER: gitea_user PASSWD: xxxxxx SCHEMA: public session: PROVIDER: memory cache: ADAPTER: memory queue: TYPE: level
NFS存储的PV/PVC配置:
apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs-cluster spec: capacity: storage: 10Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain nfs: server: nfs.example.com path: /nfs/qtest/gitea kind: PersistentVolumeClaim apiVersion: v1 metadata: name: cluster-nfs-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi
问题原因
当replicaCount>1时,Gitea Helm模板会触发分布式场景的配置逻辑,其中cron.GIT_GC_REPOS被要求为map结构(需包含ENABLED、RUN_AT等子配置项),但当前配置未显式定义该节点,模板默认填充了字符串类型值,导致渲染时类型不匹配报错。
同时,当前配置的session、cache、queue使用本地内存/文件存储,多实例场景下无法共享状态,即便解决模板报错,也会出现登录状态不一致、任务队列不同步等功能异常。
解决方案
- 修复cron配置类型错误
在gitea.config下添加cron节点,将GIT_GC_REPOS定义为map结构:
gitea: config: # 保留原有其他配置... cron: GIT_GC_REPOS: ENABLED: true RUN_AT: "0 0 * * *" # 每日凌晨执行仓库GC TIMEOUT: 86400 # 超时时间(秒)
- 调整分布式场景依赖配置
多实例必须使用共享存储的session、cache和队列,需启用Redis并修改对应配置:
- 启用Redis(替换原redis-cluster配置):
redis: enabled: true auth: enabled: false # 根据实际安全需求调整
- 修改session、cache、queue配置:
gitea: config: # 保留原有其他配置... session: PROVIDER: redis cache: ADAPTER: redis queue: TYPE: redis
额外注意事项
- NFS的
ReadWriteMany访问模式符合多实例共享存储需求,但需确保NFS服务器路径权限正确,Gitea运行用户(默认git)拥有读写权限。 - 已使用外部PostgreSQL数据库,该配置符合多实例共享要求,无需调整。
内容的提问来源于stack exchange,提问作者brancott
相关产品推荐
相关产品推荐

