首页 新闻 会员 周边 捐助

helm 部署时报错:"cannot unmarshal number into Go struct field"

0
悬赏园豆:30 [已解决问题] 解决于 2025-03-16 11:28

helm 部署园子的一个应用时出现下面的错误:

Error: UPGRADE FAILED: failed to create resource: Deployment in version "v1" cannot be handled as a Deployment: json: cannot unmarshal number into Go struct field ObjectMeta.spec.template.metadata.labels of type string

所使用的 helm chart 是一个通用的应用部署模版,已经部署过很多应用,最近也没有过变更

k8s
dudu的主页 dudu | 高人七级 | 园豆:24728
提问于:2025-03-16 10:43
< >
分享
最佳答案
0

是下面的 version 值引起的,之前版本号用的都是3位数字,比如 2.2.1,默认会解析为字符串,不会报错。这次用的是 2.3,被解析为数字,而 k8s 的 labels 不允许使用数字,所以报错。

spec:
  template:
    metadata:
      labels:
        version: {{ .Values.imageVersion }}

加上引号即可解决

version: "{{ .Values.imageVersion }}"
dudu | 高人七级 |园豆:24728 | 2025-03-16 11:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册