错误描述
在使用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
命令安装,一切又恢复正常。