【集群】K8S集群重启问题排查记录

【集群】K8S集群重启问题排查记录

Fre5h1nd Lv6

💡简介

前段时间机房断电,导致大批量服务器故障。终于恢复正常后发现服务器上的 k8s 无法连接了,因此排查并记录一下过程。

🖼️背景

  • 机房断电导致服务器重启,k8s 集群无法正常连接。
  • 需要排查权限问题、服务启动问题及解决方案。

🧠思路

  1. 检查 kubectl get node 报错,判断权限问题。
  2. 检查 kubelet 服务状态,判断服务启动问题。
  3. 检查 Docker 及相关容器状态,判断组件问题。
  4. 记录常见问题与解决方法。

🔨解决

1. 权限问题排查

使用 kubectl get node 发现报错:

1
The connection to the server localhost:8080 was refused - did you specify the right host or port?

根据博客[1,2],判断是出现权限问题,admin.conf文件未绑定,通过echo $KUBECONFIG发现无输出,证明确实是该问题。
通过以下指令绑定相应权限文件:

1
2
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
source /etc/profile

2. 服务启动问题排查

继续使用 kubectl get node 发现报错:

1
The connection to the server xx.xx.xx.xx:6443 was refused - did you specify the right host or port?

根据博客[3,4],判断是服务启动不成功。依次检查6443端口kubeletdocker及相关容器,发现全都存在问题。具体检查指令及结果如下:

检查 6443 端口
1
2
# 检查 6443 端口,发现无输出,说明无应用监听该端口。其对应的是 kubelet,说明 kubelet 可能出现了问题
$ ss -antulp | grep :6443
检查 kubelet
1
2
3
4
5
6
7
8
9
10
# 检查 kubelet,发现果然未正常启动。
$ systemctl status kubelet
# 尝试重启,再查看状态仍然未正常启动
$ systemctl restart kubelet
# 分析日志
$ journalctl -xefu kubelet
# kubelet[86499]: E0519 23:40:27.056433 86499 run.go:74] "command failed" err="failed to parse kubelet flag: unknown flag: --network-plugin"
# 查看各组件版本
$ rpm -qa | grep kube
# 看到很多博客说 Master 和 Node 节点版本不一致导致出问题,但本服务器只有一个 Master 节点,因此理论上不会有这个问题
检查 docker 及相关容器
1
2
3
4
5
6
7
8
9
10
11
$ docker ps -a | grep kube-apiserver
$ docker ps -a | grep etcd
# 发现所有容器都出于 Exit (255) 状态,判断是组件出现了问题。
# 查看 ETCD 报错日志,其中 ETCD_NAME 指上述指令中看到的 ETCD 容器名称
$ docker logs ${ETCD}
# 发现一切正常,尝试暴力重启所有组件
$ docker start $(docker ps -a | awk '{print $1}' | tail -n +2)
# 部分组件正常,部分组件报错:Error response from daemon: cannot join network of a non running container: xxx
# 猜测是启动顺序问题,重新再执行一次启动即可
$ docker start $(docker ps -a | awk '{print $1}' | tail -n +2)
# 一切恢复正常

🏥反思

  • 服务器重启后,k8s 集群可能出现权限问题、服务启动问题,需及时排查。
  • 检查 kubelet 服务状态、Docker 容器状态是排查问题的关键步骤。
  • 记录常见问题与解决方法,便于后续参考。


  • 希望这篇博客对你有帮助!如果你有任何问题或需要进一步的帮助,请随时提问。
  • 如果你喜欢这篇文章,欢迎动动小手给我一个follow或star。

🗺参考文献

[1] k8s重启导致node没有成功连接:The connection to the server localhost:8080 was refused - did you specify the righ

[2] 解决The connection to the server localhost:8080 was refused - did you specify the right host or port?

[3] k8s重启报错 :The connection to the server 192.168.102.149:6443 was refused

[4] 如何排查解决:The connection to the server <HOST>:6443 was refused - did you specify the right host or port

  • 标题: 【集群】K8S集群重启问题排查记录
  • 作者: Fre5h1nd
  • 创建于 : 2025-05-19 23:24:14
  • 更新于 : 2025-05-20 00:04:33
  • 链接: https://freshwlnd.github.io/2025/05/19/k8s/k8s-host-restart/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论