使用Helm在Kubernetes中简易部署Gitea

发布于 2023-10-07  210 次阅读


添加Helm源:

helm repo add gitea https://dl.gitea.com/charts
helm repo update

生成配置文件:

helm show values gitea/gitea > values.yaml

配置文件中要修改的部分主要为三个部分,分别为管理员用户、数据库和Ingress。

首先修改Ingress部分,先注释掉原本的ingress类。接下来在annotations中添加请求证书使用的issuer:cert-manager.io/cluster-issuer: "letsencrypt"。然后修改host中的域名为要使用的域名。最后修改tls中保存证书的机密名称和域名。修改后参考如下:

ingress:
  enabled: true
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt"
  hosts:
    - host: git.example.com
      paths:
        - path: /
          pathType: Prefix
  tls: 
    - secretName: gitea-tls
      hosts:
        - git.example.com

接下来修改默认管理员用户配置。修改用户名、密码和默认邮箱即可。示例如下:

gitea:
  admin:
    existingSecret:
    username: gitea_admin
    password: r8sA8CPHD9!bt6d
    email: "[email protected]"

最后修改数据库配置,由于是小规模部署,这里只使用普通的PostgreSQL。首先将postgresql-ha中的enabled改为false

postgresql中的enabled修改为true。然后修改数据库密码。这里可以在添加postgresPassword来为数据库设置root密码。

postgresql-ha:
  global:
    postgresql:
      database: gitea
      password: gitea
      username: gitea
  enabled: false
  postgresql:
    repmgrPassword: changeme2
    postgresPassword: changeme1
    password: changeme4
  pgpool:
    adminPassword: changeme3
  service:
    ports:
      postgresql: 5432
  primary:
    persistence:
      size: 10Gi

postgresql:
  enabled: true
  global:
    postgresql:
      auth:
        password: password
        database: gitea
        username: gitea
        postgresPassword:rootpassword
      service:
        ports:
          postgresql: 5432
  primary:
    persistence:
      size: 10Gi

保存后先创建命名空间:

kubectl create ns gitea

然后使用Helm安装:

helm -n gitea install gitea -f values.yaml gitea/gitea

之后等待gitea部署完成即可。

附:由GPT翻译的values.yaml文件

# 默认值用于gitea。
# 这是一个YAML格式的文件。
# 声明要传递到您的模板中的变量。
## @section Global
#
## @param global.imageRegistry 全局镜像仓库覆盖
## @param global.imagePullSecrets 全局镜像拉取凭据覆盖;可以由`imagePullSecrets`扩展
## @param global.storageClass 全局存储类别覆盖
## @param global.hostAliases 将添加到Pod主机文件的全局hostAliases
global:
  imageRegistry: ""
  ## 例如
  ## imagePullSecrets:
  ##   - myRegistryKeySecretName
  ##
  imagePullSecrets: []
  storageClass: ""
  hostAliases: []
  # - ip: 192.168.137.2
  #   hostnames:
  #   - example.com

## @param replicaCount 部署的副本数量
replicaCount: 1

## @section strategy
## @param strategy.type 策略类型
## @param strategy.rollingUpdate.maxSurge 最大增加数
## @param strategy.rollingUpdate.maxUnavailable 最大不可用数
strategy:
  type: "RollingUpdate"
  rollingUpdate:
    maxSurge: "100%"
    maxUnavailable: 0

## @param clusterDomain 集群域名
clusterDomain: cluster.local

## @section Image
## @param image.registry 镜像仓库,例如gcr.io,docker.io
## @param image.repository 为此Pod启动的镜像
## @param image.tag 查看:[镜像标签](https://hub.docker.com/r/gitea/gitea/tags?page=1&ordering=last_updated)。默认为Chart.yaml中的`appVersion`。
## @param image.digest 镜像摘要。允许固定给定的镜像标签。用于对可变标签(例如“latest”)具有控制权
## @param image.pullPolicy 镜像拉取策略
## @param image.rootless 是否拉取Gitea的rootless版本,仅适用于Gitea 1.14.x或更高版本
image:
  registry: ""
  repository: gitea/gitea
  # 覆盖默认的镜像标签,其默认值为chart的appVersion。
  tag: ""
  digest: ""
  pullPolicy: Always
  rootless: true

## @param imagePullSecrets 用于拉取镜像的Secret
imagePullSecrets: []

## @section Security
# 由于镜像设计的原因,安全上下文只能与rootless镜像一起使用
## @param podSecurityContext 为Pod中所有容器设置共享文件系统组。
podSecurityContext:
  fsGroup: 1000

## @param containerSecurityContext 安全上下文
containerSecurityContext: {}
#   allowPrivilegeEscalation: false
#   capabilities:
#     drop:
#       - ALL
#   # 如果要在使用容器运行时cri-o的节点上运行Pod,请为root和rootless镜像添加SYS_CHROOT功能。否则,您将从SSH服务器收到错误消息,指出无法从存储库中读取。
#   # https://gitea.com/gitea/helm-chart/issues/161
#     add:
#       - SYS_CHROOT
#   privileged: false
#   readOnlyRootFilesystem: true
#   runAsGroup: 1000
#   runAsNonRoot: true
#   runAsUser: 1000

## @deprecated 安全上下文变量已分为两部分:
## - containerSecurityContext
## - podSecurityContext。
## @param securityContext 将init和Gitea容器作为特定securityContext运行
securityContext: {}

## @param podDisruptionBudget Pod中断预算
podDisruptionBudget: {}
#  maxUnavailable: 1
#  minAvailable: 1

## @section Service
service:
  ## @param service.http.type 用于web流量的Kubernetes服务类型
  ## @param service.http.port web流量的端口号
  ## @param service.http.clusterIP http自动设置的集群IP设置为None
  ## @param service.http.loadBalancerIP LoadBalancer IP设置
  ## @param service.http.nodePort http服务的NodePort
  ## @param service.http.externalTrafficPolicy 如果`service.http.type`为`NodePort`或`LoadBalancer`,将其设置为`Local`以启用源IP保留
  ## @param service.http.externalIPs 服务的外部IP
  ## @param service.http.ipFamilyPolicy HTTP服务双栈策略
  ## @param service.http.ipFamilies HTTP服务双栈族选择,双栈参数请参阅官方kubernetes [双栈概念文档](https://kubernetes.io/docs/concepts/services-networking/dual-stack/)。
  ## @param service.http.loadBalancerSourceRanges 用于http负载均衡器的源范围过滤器
  ## @param service.http.annotations HTTP服务注解
  http:
    type: ClusterIP
    port: 3000
    clusterIP: None
    loadBalancerIP:
    nodePort:
    externalTrafficPolicy:
    externalIPs:
    ipFamilyPolicy:
    ipFamilies:
    loadBalancerSourceRanges: []
    annotations: {}
  ## @param service.ssh.type Kubernetes服务类型,用于ssh流量
  ## @param service.ssh.port ssh流量的端口号
  ## @param service.ssh.clusterIP ssh自动设置的集群IP设置为None
  ## @param service.ssh.loadBalancerIP LoadBalancer IP设置
  ## @param service.ssh.nodePort ssh服务的NodePort
  ## @param service.ssh.externalTrafficPolicy 如果`service.ssh.type`为`NodePort`或`LoadBalancer`,将其设置为`Local`以启用源IP保留
  ## @param service.ssh.externalIPs 服务的外部IP
  ## @param service.ssh.ipFamilyPolicy SSH服务双栈策略
  ## @param service.ssh.ipFamilies SSH服务双栈族选择,双栈参数请参阅官方kubernetes [双栈概念文档](https://kubernetes.io/docs/concepts/services-networking/dual-stack/)。
  ## @param service.ssh.loadBalancerSourceRanges 用于ssh负载均衡器的源范围过滤器
  ## @param service.ssh.annotations SSH服务注解
  ssh:
    type: ClusterIP
    port: 22
    clusterIP: None
    loadBalancerIP:
    nodePort:
    externalTrafficPolicy:
    externalIPs:
    ipFamilyPolicy:
    ipFamilies:
    loadBalancerSourceRanges: []
    annotations: {}

## @section Ingress
## @param ingress.enabled 启用Ingress
## @param ingress.className Ingress类名
## @param ingress.annotations Ingress注解
## @param ingress.hosts[0].host 默认的Ingress主机
## @param ingress.hosts[0].paths[0].path 默认的Ingress路径
## @param ingress.hosts[0].paths[0].pathType Ingress路径类型
## @param ingress.tls Ingress TLS设置
## @extra ingress.apiVersion 指定Ingress对象的APIVersion。通常仅用于argocd。
ingress:
  enabled: false
  className:
  annotations:
    {}
  hosts:
    - host: git.example.com
      paths:
        - path: /
          pathType: Prefix
  tls: []
  apiVersion: networking.k8s.io/v1

## @section deployment
#
## @param resources Kubernetes资源
resources:
  {}
  # 我们通常建议不指定默认资源,并将其保留为用户的有意选择。
  # 这也增加了在资源较少的环境中运行Chart的机会,例如Minikube。如果您确实想指定资源,请取消注释以下行,根据需要进行调整,并在“resources:”后的大括号中删除大括号。
  # limits:
  #   cpu: 100m
  #   memory: 128Mi
  # requests:
  #   cpu: 100m
  #   memory: 128Mi

## 使用替代调度程序,例如“stork”。
## ref: https://kubernetes.io/docs/tasks/administer-cluster/configure-multiple-schedulers/
##
## @param schedulerName 使用替代调度程序,例如“stork”
schedulerName: ""

## @param nodeSelector 节点选择器
nodeSelector: {}

## @param tolerations 容忍设置
tolerations: []

## @param affinity 亲和性设置
affinity: {}

## @param topologySpreadConstraints 部署的拓扑约束
topologySpreadConstraints: []

## @param dnsConfig DNS配置
dnsConfig: {}

## @param priorityClassName 优先级类别名称
priorityClassName: ""

## @param deployment.env  传递给容器的附加环境变量
## @param deployment.terminationGracePeriodSeconds 强制杀死Pod之前的等待时间
## @param deployment.labels 部署的标签
## @param deployment.annotations 部署的注解
deployment:
  env:
    []
  terminationGracePeriodSeconds: 60
  labels: {}
  annotations: {}

## @section ServiceAccount
## @param serviceAccount.create 启用ServiceAccount的创建
## @param serviceAccount.name 创建的ServiceAccount的名称,默认为发布名称。还可以链接到外部提供的应该使用的ServiceAccount。
## @param serviceAccount.automountServiceAccountToken 启用/禁用服务账户令牌的自动挂载
## @param serviceAccount.imagePullSecrets 图像拉取凭据,可用于ServiceAccount
## @param serviceAccount.annotations ServiceAccount的自定义注解
## @param serviceAccount.labels ServiceAccount的自定义标签
serviceAccount:
  create: false
  name: ""
  automountServiceAccountToken: false
  imagePullSecrets: []
  annotations: {}
  labels: {}

## @section Persistence
#
## @param persistence.enabled 启用持久性存储
## @param persistence.create 是否为共享存储创建持久VolumeClaim
## @param persistence.mount 是否应该挂载持久VolumeClaim(即使没有创建)
## @param persistence.claimName 使用现有的持久VolumeClaim来存储存储库信息
## @param persistence.size 持久性存储的大小以存储存储库信息
## @param persistence.accessModes 持久性存储的访问模式
## @param persistence.labels 要创建的持久卷索赔的标签
## @param persistence.annotations.helm.sh/resource-policy 持久卷索赔的资源策略
## @param persistence.storageClass 存储类别的名称
## @param persistence.subPath 要挂载的卷的子目录
## @param persistence.volumeName 持久卷中的名称
persistence:
  enabled: true
  create: true
  mount: true
  claimName: gitea-shared-storage
  size: 10Gi
  accessModes:
    - ReadWriteOnce
  labels: {}
  storageClass:
  subPath:
  volumeName: ""
  annotations:
    helm.sh/resource-policy: keep

## @param extraVolumes 要挂载到Gitea部署的额外卷
extraVolumes: []

## @param extraContainerVolumeMounts 仅映射到Gitea运行/主容器中的挂载,以覆盖自定义模板等。
extraContainerVolumeMounts: []

## @param extraInitVolumeMounts 仅映射到init容器中的挂载。可用于额外的预配置。
extraInitVolumeMounts: []

## @deprecated extraVolumeMounts变量已拆分为两个:
## - extraContainerVolumeMounts
## - extraInitVolumeMounts
## 例如,可以用于在连接到外部Postgres服务器时挂载客户端证书。
## @param extraVolumeMounts **不推荐使用** 用于init容器和Gitea主容器的额外卷挂载
extraVolumeMounts: []

## @section Init
## @param initPreScript 复制到init容器的启动时的Bash shell脚本
initPreScript: ""

## @param initContainers.resources.limits init容器的资源限制
## @param initContainers.resources.requests.cpu init容器的CPU资源限制
## @param initContainers.resources.requests.memory init容器的内存资源限制
initContainers:
  resources:
    limits: {}
    requests:
      cpu: 100m
      memory: 128Mi

# 配置提交/操作签名的前提条件
## @section Signing
#
## @param signing.enabled 启用提交/操作签名
## @param signing.gpgHome GPG主目录
## @param signing.privateKey 内联私有gpg密钥以签署Gitea操作
## @param signing.existingSecret 使用现有的秘密存储`signing.privateKey`的值
signing:
  enabled: false
  gpgHome: /data/git/.gnupg
  privateKey: ""
  existingSecret: ""

## @section Gitea
#
gitea:
  ## @param gitea.admin.username Gitea管理员用户的用户名
  ## @param gitea.admin.existingSecret 使用现有的秘密存储管理员用户凭据
  ## @param gitea.admin.password Gitea管理员用户的密码
  ## @param gitea.admin.email Gitea管理员用户的电子邮件
  admin:
    existingSecret:
    username: gitea_admin
    password: r8sA8CPHD9!bt6d
    email: "[email protected]"

  ## @param gitea.metrics.enabled 启用Gitea指标
  ## @param gitea.metrics.serviceMonitor.enabled 启用Gitea指标ServiceMonitor
  metrics:
    enabled: false
    serviceMonitor:
      enabled: false

  ## @param gitea.ldap LDAP配置
  ldap: []

  # 要么指定内联的“key”和“secret”,要么通过“existingSecret”引用它们
  ## @param gitea.oauth OAuth配置
  oauth: []

  ## @param gitea.config.server.SSH_PORT 用于rootful Gitea镜像的SSH端口
  ## @param gitea.config.server.SSH_LISTEN_PORT 用于rootless Gitea镜像的SSH端口
  config:
    server:
      SSH_PORT: 22
      SSH_LISTEN_PORT: 2222

  ## @param gitea.additionalConfigSources 从秘密或ConfigMap获取的额外配置
  additionalConfigSources: []

  ## @param gitea.additionalConfigFromEnvs 从环境变量获取的额外配置源
  additionalConfigFromEnvs: []

  ## @param gitea.podAnnotations Gitea Pod的注解
  podAnnotations: {}

  ## @param gitea.ssh.logLevel 配置OpenSSH的日志级别,仅适用于基于root的Gitea镜像
  ssh:
    logLevel: "INFO"

  ## @section LivenessProbe
  #
  ## @param gitea.livenessProbe.enabled 启用活跃性探测
  ## @param gitea.livenessProbe.tcpSocket.port 用于活跃性探测的端口
  ## @param gitea.livenessProbe.initialDelaySeconds 活跃性探测启动前的初始延迟
  ## @param gitea.livenessProbe.timeoutSeconds 活跃性探测超时
  ## @param gitea.livenessProbe.periodSeconds 活跃性探测周期
  ## @param gitea.livenessProbe.successThreshold 活跃性探测成功阈值
  ## @param gitea.livenessProbe.failureThreshold 活跃性探测失败阈值
  livenessProbe:
    enabled: true
    tcpSocket:
      port: http
    initialDelaySeconds: 200
    timeoutSeconds: 1
    periodSeconds: 10
    successThreshold: 1
    failureThreshold: 10
  ## @section ReadinessProbe
  #
  ## @param gitea.readinessProbe.enabled 启用可读性探测
  ## @param gitea.readinessProbe.tcpSocket.port 用于可读性探测的端口
  ## @param gitea.readinessProbe.initialDelaySeconds 可读性探测启动前的初始延迟
  ## @param gitea.readinessProbe.timeoutSeconds 可读性探测超时
  ## @param gitea.readinessProbe.periodSeconds 可读性探测周期
  ## @param gitea.readinessProbe.successThreshold 可读性探测成功阈值
  ## @param gitea.readinessProbe.failureThreshold 可读性探测失败阈值
  readinessProbe:
    enabled: true
    tcpSocket:
      port: http
    initialDelaySeconds: 5
    timeoutSeconds: 1
    periodSeconds: 10
    successThreshold: 1
    failureThreshold: 3

  ## @section redis-cluster
  ## @param redis-cluster.enabled 启用redis
  ## @param redis-cluster.usePassword 是否使用密码进行身份验证
  redis-cluster:
    enabled: true
    usePassword: false

  ## @section postgresql-ha
  #
  ## @param postgresql-ha.enabled 启用postgresql-ha
  ## @param postgresql-ha.postgresql.password `gitea`用户的密码(覆盖`auth.password`)
  ## @param postgresql-ha.global.postgresql.database 要创建的自定义数据库的名称(覆盖`auth.database`)
  ## @param postgresql-ha.global.postgresql.username 要创建的自定义用户的名称(覆盖`auth.username`)
  ## @param postgresql-ha.global.postgresql.password 要创建的自定义密码的名称(覆盖`auth.password`)
  ## @param postgresql-ha.postgresql.repmgrPassword Repmgr密码
  ## @param postgresql-ha.postgresql.postgresPassword postgres密码
  ## @param postgresql-ha.pgpool.adminPassword pgpool admin密码
  ## @param postgresql-ha.service.ports.postgresql postgresql服务端口(覆盖`service.ports.postgresql`)
  ## @param postgresql-ha.primary.persistence.size postgresql-ha卷的PVC存储请求
  postgresql-ha:
    global:
      postgresql:
        database: gitea
        password: gitea
        username: gitea
    enabled: true
    postgresql:
      repmgrPassword: changeme2
      postgresPassword: changeme1
      password: changeme4
    pgpool:
      adminPassword: changeme3
    service:
      ports:
        postgresql: 5432
    primary:
      persistence:
        size: 10Gi

  ## @section PostgreSQL
  #
  ## @param postgresql.enabled 启用PostgreSQL
  ## @param postgresql.global.postgresql.auth.password `gitea`用户的密码(覆盖`auth.password`)
  ## @param postgresql.global.postgresql.auth.database 要创建的自定义数据库的名称(覆盖`auth.database`)
  ## @param postgresql.global.postgresql.auth.username 要创建的自定义用户的名称(覆盖`auth.username`)
  ## @param postgresql.global.postgresql.service.ports.postgresql PostgreSQL服务端口(覆盖`service.ports.postgresql`)
  ## @param postgresql.primary.persistence.size PostgreSQL卷的PVC存储请求
  postgresql:
    enabled: false
    global:
      postgresql:
        auth:
          password: gitea
          database: gitea
          username: gitea
        service:
          ports:
            postgresql: 5432
    primary:
      persistence:
        size: 10Gi

## 默认情况下,已删除或已移动的设置仍然保留在用户定义的values.yaml中,将导致Helm运行安装/更新失败。
## 将其设置为false以跳过此基本验证检查。
## @section Advanced
## @param checkDeprecation 将其设置为false以跳过此基本验证检查。
## @param test.enabled 将其设置为false以禁用test-connection Pod。
## @param test.image.name 用于test-connection Pod中的wget容器的镜像名称
## @param test.image.tag 用于test-connection Pod中的wget容器的镜像标签
checkDeprecation: true
test:
  enabled: true
  image:
    name: busybox
    tag: latest

## @param extraDeploy 要与发布一起部署的额外对象数组
##
extraDeploy: []

参考文档

Helm chart for gitea

使用官方 Helm Chart 安装 Gitea

使用 Helm 在 Kubernetes 云原生环境中安装 Gitea