如何通过 --set 命令行参数在 Helm chart 中设置 ingress.hosts[0].host

How to set ingress.hosts[0].host in Helm chart via --set command line argument

在 Helm 图表中,当尝试通过 --set 命令行参数设置“ingress.hosts[0].host”时,values.yaml 中指定的“路径”数组值文件不会添加到最终输出中。

我想覆盖“ingress.hosts[0].host”键,以便在命令行上部署到不同的 DNS 区域。如果我将主机添加到 values.yaml 文件,它会生成正确的入口,但这意味着有不同的 values.yaml 文件而不是重新使用相同的文件,但具有不同的 DNS 区域。

ingress.yaml 头盔模板

rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
            pathType: {{ .pathType }}
            {{- end }}
            backend:
              {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
              service:
                name: {{ $fullName }}
                port:
                  number: {{ $svcPort }}
              {{- else }}
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
              {{- end }}
          {{- end }}
    {{- end }}

values.yaml(注意应添加到 deployment.yaml 文件的单个“路径”对象)。

ingress:
  enabled: true
  className: ""
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
  hosts:
  - host: 
    paths:
    - path: "/"
      pathType: Prefix

命令行

helm template ./deploy/vehicleregistrationservice --set ingress.hosts[0].host=vehicleregistrationservice.aksapp.io --debug

部署文件无效(注意“路径”数组是空的)

kind: Ingress
metadata:
  name: vehicleregistrationservice
  labels:
    helm.sh/chart: vehicleregistrationservice-0.1.0
    app.kubernetes.io/name: vehicleregistrationservice
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
spec:
  rules:
    - host: "vehicleregistrationservice.aksapp.io"
      http:
        paths:

部署文件应该如下所示:

kind: Ingress
metadata:
  name: vehicleregistrationservice
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
spec:
  rules:
  - host: vehicleregistrationservice.aksapp.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service: 
            name: vehicleregistrationservice
            port: 
              number: 80

刚遇到同样的问题。

试试 --set "ingress.hosts[0].host=yourhost.com,ingress.hosts[0].paths[0].path=/"