You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从v1beta1升级到v1后Helm Ingress Chart部署报错求助

解决Helm Ingress从v1beta1升级到v1的配置错误

从networking.k8s.io/v1beta1升级到v1后,Ingress资源的结构和必填项有两处关键变更,加上你的values文件结构与模板不匹配,导致了报错:

  • Backend结构变更:不再支持serviceName/servicePort字段,需改用嵌套的service.name和service.port.number
  • 必填字段新增:pathType为必填项(可选值:ImplementationSpecific、Exact、Prefix)
  • Values结构不匹配:你在host下添加的http层级与模板遍历逻辑冲突,导致模板无法读取paths数据

1. 修正后的Ingress模板(templates/ingress.yaml)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Values.ingress.name }}
  annotations:
    kubernetes.io/ingress.class: {{ .Values.ingress.annotations.class }}
spec:
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
        {{- range .paths }}
          - path: {{ .path }}
            pathType: {{ .pathType }}
            backend:
              service:
                name: {{ .backend.serviceName }}
                port:
                  number: {{ .backend.servicePort }}
        {{- end }}
  {{- end }}

2. 修正后的values.yaml

ingress:
  name: ingress-service
  replicaCount: 1
  annotations: 
    class: nginx
  hosts:
    - host: chart-example.local
      paths: 
        - path: /
          pathType: ImplementationSpecific
          backend:
            serviceName: serviceName
            servicePort: 8080

3. 修正后的外部ingress.yaml(helm install -f指定的文件)

ingress:
  hosts:
    - host: adminer.k8s.com
      paths:
        - path: /
          pathType: ImplementationSpecific
          backend:  
            serviceName: adminer
            servicePort: 8080
    - host: kanban.k8s.com
      paths: 
        - path: /api/
          pathType: Prefix
          backend:
            serviceName: kanban-app
            servicePort: 8080
        - path: /
          pathType: Prefix
          backend:
            serviceName: kanban-ui
            servicePort: 80

关键说明

  • 模板中把backend.serviceName改为backend.service.name,servicePort改为service.port.number,完全适配v1版本的资源结构
  • pathType根据路由需求选择:
    • ImplementationSpecific:由Ingress控制器决定匹配规则(兼容旧版v1beta1的行为)
    • Prefix:前缀匹配(比如/api/会匹配所有/api/xxx路径)
    • Exact:精确匹配指定路径
  • 去掉host下的http层级,确保模板能正确遍历.Values.ingress.hosts[].paths数据,解决spec.rules[0].http.paths: Required value错误

最后执行安装命令:

helm install -f ingress.yaml ingress ./ingress

内容的提问来源于stack exchange,提问作者Martin Specker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 15:24:51