请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

服务器重启后怎么加入节点

问题描述:
1、由于服务器重启后,我将Node2加入节点,kubectl get nodes结果如下:node1的状态变为了NotReady;
[root@node1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 2d2h v1.19.3
node1 NotReady 31h v1.19.3
node2 Ready 16m v1.19.3

2、然后我重启node1的docker和kubelet,发现kebelet的状态是loaded;
[root@node1 ~]# systemctl start docker && systemctl start kubelet
[root@node1 ~]# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since Mon 2022-08-15 00:57:14 CST; 109ms ago
Docs: https://kubernetes.io/docs/
Main PID: 37175 (kubelet)
Tasks: 7
Memory: 17.3M
CGroup: /system.slice/kubelet.service
└─37175 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --networ…

Aug 15 00:57:14 node1 systemd[1]: Started kubelet: The Kubernetes Node Agent.
Aug 15 00:57:14 node1 kubelet[37175]: I0815 00:57:14.971612 37175 server.go:411] Version: v1.19.3
Aug 15 00:57:14 node1 kubelet[37175]: I0815 00:57:14.971826 37175 server.go:831] Client rotation is on, will bootstrap in background
Aug 15 00:57:14 node1 kubelet[37175]: I0815 00:57:14.979889 37175 certificate_store.go:130] Loading cert/key pair from “/var/lib/kubelet/pki/kubelet-client-current.pem”.
Aug 15 00:57:14 node1 kubelet[37175]: I0815 00:57:14.982702 37175 dynamic_cafile_content.go:167] Starting client-ca-bundle::/etc/kubernetes/pki/ca.crt

3、我搜索了一下,说是需要关闭swap,我执行
[root@node1 ~]# journalctl -xefu kubelet ## 查看kubelet日志。
[root@node1 ~]# swapoff -a ## 关闭swap
结果竟然可以启动了,但是还是没有加入集群节点;

4、我就在node1节点,再次执行如下命令,还是不行,报错如下:/etc/kubernetes/kubelet.conf already exists

[root@node1 ~]# kubeadm join 192.168.31.162:6443 --token jhltn4.yk9lmi0fwzc4t7wm --discovery-token-ca-cert-hash sha256:b5c7c6dc495966df7d3191e0acd2cf1c8de0febffcbc9ea5ec50c2fc80422fbb
[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/
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR FileAvailable–etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
[ERROR FileAvailable–etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
[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

希望老师解答一下:
1、如果服务器重启后是不是需要重新加入集群节点?具体该怎么做。
2、如果master执行: kubeadm token create --print-join-command命令,通过生成的token,两个work节点可以共用吗,还是需要分别生成不同的token。

正在回答

1回答

提示错误etc/kubernetes/kubelet.conf already exists,需要删除这个文件,或者kubeadm reset.

节点重启后要看下flannel 是否起来,没有的话需要kube apply flanne.yml

1 回复 有任何疑惑可以回复我~
  • [root@node1 ~]# rm -f /etc/kubernetes/kubelet.conf
    
    [root@node1 ~]# rm -f /etc/kubernetes/pki/ca.crt
    
    [root@node1 ~]# kubeadm join 192.168.31.162:6443 --token jhltn4.yk9lmi0fwzc4t7wm     --discovery-token-ca-cert-hash sha256:b5c7c6dc495966df7d3191e0acd2cf1c8de0febffcbc9ea5ec50c2fc80422fbb
    [root@node1 ~]# kubectl get nodes
    NAME     STATUS   ROLES    AGE    VERSION
    master   Ready    master   2d2h   v1.19.3
    node1    Ready    <none>   31h    v1.19.3
    node2    Ready    <none>   30m    v1.19.3
    
    这样操作就可以了,对不对。
    回复 有任何疑惑可以回复我~ 2022-08-14 17:34:02
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信