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

如何修复用于添加Longhorn注解的Kubernetes节点补丁文件?

解决Kubectl Patch节点添加Longhorn多磁盘注解时的Unmarshal错误

错误原因

Kubernetes的metadata.annotations字段要求所有值必须是字符串类型,你当前的补丁文件将node.longhorn.io的值定义为嵌套对象,导致Go结构体无法将对象解析为字符串,触发json: cannot unmarshal object into Go struct field ObjectMeta.metadata.annotations of type string错误。

修复后的补丁文件

修正三个核心问题:

  1. 使用Longhorn官方指定的注解键node.longhorn.io/default-disks-config
  2. 将多磁盘配置转为JSON格式的字符串(通过YAML多行字符串语法|维护可读性)
  3. 修正拼写错误:allowSheduling → allowScheduling
metadata:
  annotations:
    node.longhorn.io/default-disks-config: |
      [
        {
          "path": "/mnt/lh01",
          "allowScheduling": true
        },
        {
          "path": "/mnt/lh02",
          "allowScheduling": true
        }
      ]

执行命令

保持原命令不变:

kubectl patch node k8s-worker-1 --type merge --patch-file /home/bino/k0s-sriwijaya/longhorn/lhpatch.yaml

内容的提问来源于stack exchange,提问作者Bino Oetomo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 16:39:46