初始化k8s踩过的坑

问题一:error execution phase preflight: couldn‘t validate the identity of the API Server: abort connecting

这个问题网上有很多的解决方法,大致有以下几种:
前两种网上有解决方法(这里参考这篇博客1),这里不再赘述,第三种是我遇到的,由于没有同步节点之间的时间而导致

1)token 过期

2)k8s api server不可达

3) node节点与master节点的时间不同步

同步时间参考了这篇博客

问题二:node1节点join成功后,master节点中未显示node1节点

此时node1节点已成功接入到集群中,但由于node1节点与master节点的主机名相同,所以只显示了一个。只需要修改节点的hostname即可

hostnamectl --static set-hostname master
hostnamectl --static set-hostname node1

最后再重新执行kubeadm init ,重新初始化集群,node1节点重新kubeadm join加入集群
参考博客2

重新init后又出现新的的问题

[root@master ~]# kubeadm init --apiserver-advertise-address=192.168.237.125 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.20.2 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.20.2
[preflight] Running pre-flight checks
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
        [WARNING FileExisting-socat]: socat not found in system path
        [WARNING Hostname]: hostname "k8s-master" could not be reached
        [WARNING Hostname]: hostname "k8s-master": lookup k8s-master on 114.114.114.114:53: no such host
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR Port-10250]: Port 10250 is in use
        [ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

问题三:[ERROR Port-10250]: Port 10250 is in use

端口被占有

使用kubeadm reset重置节点
参考博客3

问题四:[ERROR DirAvailable–var-lib-etcd]: /var/lib/etcd is not empty

/var/lib/etcd非空,使用rm -rf 删除即可

rm -rf /var/lib/etcd

参考博客4

你可能感兴趣的:(k8s,kubernetes)