手把手教你玩转 Gitea|使用 Helm 在 K3s 上安装 Gitea( 二 )


# 打开 Ingressingress:enabled: truehosts:- host: git.example.compaths:- path: /pathType: Prefix# 打开持久存储persistence:enabled: trueexistingClaim:size: 10GiaccessModes:- ReadWriteOncelabels: {}annotations: {}storageClass:subPath:# 设置管理员账号和密码gitea:admin:username: gitea_adminpassword: r8sA8CPHD9!bt6demail: "gitea@example.com"# 设置 Gitea 的配置文件 app.iniconfig:APP_NAME: "My Git Repository"# 开启 memcachedmemcached:enabled: trueservice:port: 11211# 开启 postgresqlpostgresql:enabled: trueglobal:postgresql:postgresqlDatabase: giteapostgresqlUsername: giteapostgresqlPassword: giteaservicePort: 5432persistence:size: 10Gi重要参数说明:

  • ingress:集成负载均衡和域名绑定;
  • persistence:数据持久化存储 。请注意,persistence 中留空的 storageClass 将导致 Kubernetes 使用默认 storageClass;
  • gitea:是 Gitea 的配置内容,包括 admin、metrics、oauth 和 config 等 。其中 config 映射了 app.ini 配置参数,这些内容最后都会有 app.ini 文件的形式呈现;
  • memcached:用于数据缓存 。一旦启用这项配置 , 会自动在 app.ini 中生成下面的配置:
[cache]ADAPTER = memcacheENABLED = trueHOST = RELEASE-NAME-memcached.default.svc.cluster.local:11211
  • postgresql:开启 PostgreSQL 作为外部数据库
上述配置参数只做演示用,实际部署时需要根据自己的需求来决定安装哪些组件以及 PVC 的类型和容量 。更多配置参数请阅读:https://gitea.com/gitea/helm-chart
用 Helm 安装 Gitea先创建一个 namespace:
kubectl create ns gitea执行 helm install 命令,安装 Gitea:
$ helm install gitea --namespace gitea -f gitea.yaml gitea/giteaNAME: giteaLAST DEPLOYED: Wed Oct 12 13:19:29 2022NAMESPACE: giteaSTATUS: deployedREVISION: 1NOTES:1. Get the application URL by running these commands:http://git.example.com/在 gitea namespace 下面会有 3 个 pod 生成:
$ kubectl -n gitea get podsNAMEREADYSTATUSRESTARTSAGEgitea-memcached-77fc54d6fb-sft9q1/1Running03m20sgitea-postgresql-01/1Running03m20sgitea-01/1Running03m20s整个过程会完成 Gitea 的初始化,可以在 pod 的 log 中进行查看:
$ kubectl -n gitea logs -f gitea-0Defaulted container "gitea" out of: gitea, init-directories (init), init-app-ini (init), configure-gitea (init)Generating /data/ssh/ssh_host_ed25519_key...Generating /data/ssh/ssh_host_rsa_key...Generating /data/ssh/ssh_host_dsa_key...Generating /data/ssh/ssh_host_ecdsa_key...Server listening on :: port 22.Server listening on 0.0.0.0 port 22.2022/10/12 05:21:02 cmd/web.go:106:runWeb() [I] Starting Gitea on PID: 172022/10/12 05:21:02 cmd/web.go:157:runWeb() [I] Global init查看 Ingress 状态:
$ kubectl -n gitea get ingressNAMECLASSHOSTSADDRESSPORTSAGEgitea<none>git.example.com192.168.3.1028011m将域名解析到 Ingress 之后可以使用 http://git.example.com 登录 Gitea 实例 。
手把手教你玩转 Gitea|使用 Helm 在 K3s 上安装 Gitea

文章插图
至此,在 Kubernetes 上成功安装了 Gitea 实例,接下来就可以开启 Gitea 之旅了 。
正如开头所说,如果是生产级别的使用,需要根据每个公司的具体场景需求来做一些额外的配置 , 比如 PVC、LDAP、OAuth2、SMTP 等,这些也只需要修改 values.yaml 文件进行安装即可 。
【手把手教你玩转 Gitea|使用 Helm 在 K3s 上安装 Gitea】

推荐阅读