使用eksctl通过YAML配置创建AWS EKS节点组时遭遇JSON解组错误的求助
你遇到的问题本质不是YAML被当成JSON解析,而是配置字段不符合eksctl v1alpha5版本的Schema要求——eksctl内部会把YAML转成JSON格式做校验,所以报错信息里才会提到JSON相关内容。我帮你梳理下问题根源和修复方案:
先回顾下你的报错场景
你执行的命令:
eksctl create nodegroup -f K8s-nodegroups/group_test.yaml
先后出现两个错误:
couldn't create node group filter from command line options: loading config file "K8s-nodegroups/group_test.yaml": error unmarshaling JSON: while decoding JSON: json: unknown field "fullEc2Access"
移除fullEc2Access后又出现:
...error unmarshaling JSON: while decoding JSON: json: unknown field "spot"
错误原因与修复
1. fullEc2Access 字段问题
在eksctl v1alpha5的配置规范中,fullEc2Access 不是节点组的顶层字段,它属于IAM附加策略的配置项,需要嵌套在 iam.withAddonPolicies 下,而且字段名是驼峰写法的 fullEC2Access(注意EC2是大写)。
2. spot 字段问题
v1alpha5版本里没有直接的 spot: true 配置项,要启用竞价实例,需要使用 capacityType 字段,取值为 SPOT(对应竞价实例),如果是按需实例则用 ON_DEMAND。
修正后的完整YAML配置
apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: some-cluster-name region: eu-west-2 nodeGroups: - name: "group-test" instanceType: t3.small desiredCapacity: 1 subnets: - eu-west-2a - eu-west-2b maxSize: 2 minSize: 1 capacityType: SPOT # 替换原spot: true配置 iam: withAddonPolicies: fullEC2Access: true # 修正字段位置与命名 maxPodsPerNode: 100 volumeSize: 8 volumeType: gp3 labels: { group: test }
你可以用这个修正后的配置重新执行命令,应该就能正常创建节点组了。另外建议你核对eksctl对应版本的配置规范,确保字段符合要求,不过你使用的0.128.0和0.131.0版本都兼容v1alpha5,这个配置是没问题的。
备注:内容来源于stack exchange,提问作者prosto.vint

