可以修改生成的 helm 模板吗?

Possible to modify generated helm template?

我正在使用静态 yaml 文件来安装 gitlab。所以我运行

helm template gitlab gitlab/gitlab -f "config.yaml" > gitlab.yaml

但是在这个生成的yaml文件中我总是要修改这三个值:

apiVersion: v1
kind: Service
metadata:
  name: gitlab-gitlab-shell
  namespace: gitlab # <--- change
  labels:
    app: gitlab-shell
    chart: gitlab-shell-4.4.2
    release: gitlab
    heritage: Helm
  annotations:
    environment: prod
spec:
  type: NodePort # <--- change
  ports:
    - port: 30022
      targetPort: 2222
      protocol: TCP
      nodePort: 30022 # <-- add
      name: ssh
  selector:
    app: gitlab-shell
    release: gitlab

可以'automate'吗?也许直接在配置文件中?

这是我的 config.yaml 的样子:

global:
  edition: ce
  hosts:
    domain: domain.com

  shell:
    port: 30022

  pod:
    labels:
      environment: prod

  deployment:
    annotations:
      environment: prod

  service:
    annotations:
      environment: prod

  ingress:
    class: nginx
    configureCertmanager: false
    annotations:
      cert-manager.io/cluster-issuer: letsencrypt-prod
      acme.cert-manager.io/http01-edit-in-place: 'true'

certmanager:
  install: false

nginx-ingress:
  enabled: false

gitlab:
  webservice:
    ingress:
      tls:
        secretName: gitlab-webservice-tls
  gitaly:
    persistence:
      size: 2Gi

gitlab-runner:
  runners:
    privileged: true

registry:
  ingress:
    tls:
      secretName: gitlab-registry-tls

postgresql:
  persistence:
    size: 2Gi
minio:
  ingress:
    tls:
      secretName: gitlab-minio-tls
  persistence:
    size: 2Gi
redis:
  persistence:
    size: 2Gi

prometheus:
  alertmanager:
    enabled: false
    persistentVolume:
      enabled: false
      size: 2Gi
  pushgateway:
    enabled: false
    persistentVolume:
      enabled: false
      size: 2Gi
  server:
    persistentVolume:
      enabled: true
      size: 2Gi

一般来说,很难修改 Helm chart 的 output。您可以使用 Helm 模板语法配置图表作者特别允许的内容,但不能进行任意更改。

通常我希望图表根本不包含明确的 namespace:,并遵守 helm install --namespace 选项(helm template 有类似的选项)。配置服务非常常见,我希望图表有相应的设置。

如果您使用的是官方GitLab cloud native Helm Chart then it has a lot of settings, including specifically for the GitLab Shell chart。在您的 values.yaml 文件中,您应该能够指定

gitlab-shell:
  service:
    type: NodePort
    nodePort: 30022

(这些是特定于此图表的特定配置选项,因为图表作者已将它们设为可配置,而不是编辑生成对象的通用方式。)

通常,大规模部署中的所有相关对象都需要位于同一个命名空间中。我没有看到手动配置 GitLab shell 子图命名空间的选项,这确实有点不寻常;例如,如果它需要访问全局 GitLab ConfigMap,则它们必须位于相同的命名空间中。在您的特定示例中,服务和绑定到它的 Pods 需要位于同一名称空间中。我希望您可以使用 helm install -n 选项将 所有内容 移动到不同的命名空间,但不是基于每个组件。