如何修复用于添加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错误。
修复后的补丁文件
修正三个核心问题:
- 使用Longhorn官方指定的注解键
node.longhorn.io/default-disks-config - 将多磁盘配置转为JSON格式的字符串(通过YAML多行字符串语法
|维护可读性) - 修正拼写错误:
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
相关产品推荐
相关产品推荐

