k8s学习记录:cannot unmarshal number into Go struct field HostCfg.spec.hosts.password of type string

错误描述

在使用KubeSphere搭建多节点集群时,明明一切都是按照官方文档步骤来的,编写完config-sample.yaml配置后,使用命令./kk create cluster -f config-sample.yaml启动时遇到如下报错:在这里插入图片描述

[root@master kubeSphereSpace]# ./kk create cluster -f config-sample.yaml
Error: Failed to download cluster config: Failed to unmarshal configuration: json: cannot unmarshal number into Go struct field HostCfg.spec.hosts.password of type string
Usage:
  kk create cluster [flags]

Flags:
      --container-manager string   Container runtime: docker, crio, containerd and isula. (default "docker")
      --download-cmd string        The user defined command to download the necessary binary files. The first param '%s' is output path, the second param '%s', is the URL (default "curl -L -o %s %s")
  -f, --filename string            Path to a configuration file
  -h, --help                       help for cluster
      --skip-pull-images           Skip pre pull images
      --with-kubernetes string     Specify a supported version of kubernetes (default "v1.21.5")
      --with-kubesphere            Deploy a specific version of kubesphere (default v3.2.0)
      --with-local-storage         Deploy a local PV provisioner
  -y, --yes                        Skip pre-check of the installation

Global Flags:
      --debug        Print detailed information (default true)
      --in-cluster   Running inside the cluster

Failed to download cluster config: Failed to unmarshal configuration: json: cannot unmarshal number into Go struct field HostCfg.spec.hosts.password of type string

我的config-sample.yaml内容如下所示:

apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: master, address: 192.168.132.128, internalAddress: 192.168.132.128, user: root, password: 123456}
  - {name: node1, address: 192.168.132.129, internalAddress: 192.168.132.129, user: root, password: 123456}
  - {name: node2, address: 192.168.132.130, internalAddress: 192.168.132.130, user: root, password: 123456}
  roleGroups:
    etcd:
    - master
    master:
    - master
    worker:
    - node1
    - node2
  controlPlaneEndpoint:
    ##Internal loadbalancer for apiservers
    #internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.21.5
    clusterName: cluster.local
  network:
    plugin: calico
    kubePodsCIDR: 10.233.64.0/18
    kubeServiceCIDR: 10.233.0.0/18
  registry:
    registryMirrors: []
    insecureRegistries: []
  addons: []

---
......

解决办法

从报错信息Failed to download cluster config: Failed to unmarshal configuration: json: cannot unmarshal number into Go struct field HostCfg.spec.hosts.password of type string,能得到如下结论:由于把数字类型的密码赋值给字符串类型,从而导致报错(虽然没学过go,但意思应该是这样的)。使用vim打开config-sample.yaml,如下图所示:
在这里插入图片描述
很明显,密码部分是红色的,接下来把每个主机的密码都改为带字母的,发现颜色改变了,如下图所示:
在这里插入图片描述
之后再使用./kk create cluster -f config-sample.yaml命令安装,一切又恢复正常。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值