重新启动后如何正确恢复K8s集群?

时间:2020-01-15 09:26:02

标签: kubernetes

我有一个正常运行的K8s集群,但是由于电源故障,所有节点都重新启动了。

此刻,我在恢复主节点(和其他节点)时遇到一些问题:

  1. sudo systemctl kubelet status返回Unknown operation kubelet.,但是当我运行kubeadm init ...(用于设置集群的命令)时,它返回:
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR Port-6443]: Port 6443 is in use
    [ERROR Port-10251]: Port 10251 is in use
    [ERROR Port-10252]: Port 10252 is in use
    [ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists
    [ERROR FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml]: /etc/kubernetes/manifests/kube-controller-manager.yaml already exists
    [ERROR FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml]: /etc/kubernetes/manifests/kube-scheduler.yaml already exists
    [ERROR FileAvailable--etc-kubernetes-manifests-etcd.yaml]: /etc/kubernetes/manifests/etcd.yaml already exists
    [ERROR Port-10250]: Port 10250 is in use
    [ERROR Port-2379]: Port 2379 is in use
    [ERROR Port-2380]: Port 2380 is in use
    [ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty

当我检查这些端口时,我可以看到kubelet和其他K8s组件正在使用它们:

~/k8s-multi-node$ sudo lsof -i :10251
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kube-sche 26292 root    3u  IPv6 104933      0t0  TCP *:10251 (LISTEN)

~/k8s-multi-node$ sudo lsof -i :10252
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kube-cont 26256 root    3u  IPv6 115541      0t0  TCP *:10252 (LISTEN)

~/k8s-multi-node$ sudo lsof -i :10250
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kubelet 24781 root   27u  IPv6 106821      0t0  TCP *:10250 (LISTEN)

我试图杀死它们,但它们再次开始使用这些端口。

  1. 第二个问题是由于电源故障,我的机器目前无法访问互联网。

那么恢复这种群集的正确方法是什么?我是否需要删除kubelet和所有其他组件并再次安装?

1 个答案:

答案 0 :(得分:3)

您需要先使用sudo systemctl stop kubelet.service

停止kubelet

此后,先运行kubeadm reset,然后运行kubeadm init。请注意,这将清理现有集群并完全创建一个新集群。

关于正确的恢复方法,请检查此question