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

部署Kubernetes集群故障案例


在使用 k8s的过程中,相信很多人都遇到过使用 kubeadm join命令,将 node加入 master时,出现 error execution phase preflight: couldn't validate the identity of the API Server: abort connecting to API servers after timeout of 5m0s错误,即节点纳入管理失败,五分钟后超时放弃连接。具体信息如下

```bash
[root@node1 ~]# kubeadm join 192.168.8.120:6443 --token m1xenp.ra8y9d28h88dyfe6     --discovery-token-ca-cert-hash sha256:7dab997afd127fc4c9921808d04be57953694cc694a99c46925ae0f2b50e4308 
[preflight] Running pre-flight checks
	[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.12. Latest validated version: 19.03
	[WARNING Hostname]: hostname "node1.example.com" could not be reached
	[WARNING Hostname]: hostname "node1.example.com": lookup node1.example.com on 192.168.8.2:53: no such host
error execution phase preflight: couldn't validate the identity of the API Server: could not find a JWS signature in the cluster-info ConfigMap for token ID "m1xenp"
To see the stack trace of this error execute with --v=5 or higher

出现该问题的原因有很多,但主要有两个:

1. token 过期

此时需要通过kubedam重新生成token

//解决方法
//master主机上重新生成token
[root@master ~]# kubeadm token generate   #生成toke
fen9ed.98vjvkhle103ufht   #下面这条命令中会用到该结果
[root@master ~]# kubeadm token create fen9ed.98vjvkhle103ufht --print-join-command --ttl=0   #根据token输出添加命令
kubeadm join 192.168.8.120:6443 --token fen9ed.98vjvkhle103ufht     --discovery-token-ca-cert-hash sha256:7dab997afd127fc4c9921808d04be57953694cc694a99c46925ae0f2b50e4308 

然后用上面输出的kubeadm join命令放到想要添加的节点中执行

//问题完美解决
[root@node1 ~]# kubeadm join 192.168.8.120:6443 --token fen9ed.98vjvkhle103ufht     --discovery-token-ca-cert-hash sha256:7dab997afd127fc4c9921808d04be57953694cc694a99c46925ae0f2b50e4308 
[preflight] Running pre-flight checks
	[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.12. Latest validated version: 19.03
	[WARNING Hostname]: hostname "node1.example.com" could not be reached
	[WARNING Hostname]: hostname "node1.example.com": lookup node1.example.com on 192.168.8.2:53: no such host
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

[root@node1 ~]# 

[root@master ~]# kubectl get nodes
NAME                 STATUS   ROLES                  AGE   VERSION
master.example.com   Ready    control-plane,master   45h   v1.20.0
node1.example.com    Ready    <none>                 20m   v1.20.0
node2.example.com    Ready    <none>                 44h   v1.20.0
[root@master ~]# 

2. k8s api server不可达

此时需要检查和关闭所有服务器的firewalldselinux

[root@master ~]#setenforce 0
[root@master ~]#sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
[root@master ~]#systemctl disable firewalld --now
### 解决方案 #### Docker 版本不兼容问题 在 Kubernetes 的官方文档中提到,某些特定版本的 Docker 可能存在未经过验证的情况。当前环境中使用的 `Docker version 28.0.2` 并未被验证为与 Kubernetes 兼容[^3]。为了确保稳定性,建议降级至最新已验证的 Docker 版本(如 `20.10.x`)。以下是操作方法: 1. 卸载现有 Docker 版本: ```bash sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine ``` 2. 安装指定版本的 Docker: ```bash sudo yum install -y docker-ce-20.10.* docker-ce-cli-20.10.* containerd.io ``` 3. 启动并设置开机自启: ```bash systemctl start docker && systemctl enable docker ``` 完成上述步骤后,需重启所有节点以使更改生效。 --- #### API Server 身份验证错误解决方案 此问题通常由以下两种原因之一引起:Token 过期或 kube-apiserver 不可达[^4]。针对这两种情况分别提供了解决办法。 ##### Token 过期处理 当工作节点尝试通过过期的 Token 加入主控节点时会触发该错误。可以通过刷新 Token 来解决问题: ```bash kubeadm token create --print-join-command ``` 执行以上命令将在终端打印新的 Join 命令,将其复制并在工作节点上运行即可成功加入集群。 ##### Kube-apiserver 不可达排查 如果确认 Token 正常但仍无法连接,则可能是由于 kube-apiserver 服务异常或者网络配置不当所致。按照以下流程逐一检查: 1. **验证 kube-apiserver 是否正常运行** 使用以下命令查看其状态: ```bash systemctl status kube-apiserver ``` 如果发现停止或崩溃现象,请依据日志定位根本原因并修复。 2. **测试主机间连通性** 利用 curl 工具检测 Master 节点上的 API 地址是否可访问: ```bash curl https://<Master_IP>:6443/version --cacert /etc/kubernetes/pki/ca.crt ``` 若返回 JSON 数据则表明通信无误;反之应进一步分析防火墙规则、证书路径等问题[^2]。 3. **调整 DNS 设置** 确认 `/etc/resolv.conf` 文件中的 nameserver 参数指向合法公共 DNS 或内部解析服务器地址。 --- ### 总结 综上所述,对于 `couldn't validate the identity of the API Server` 错误,优先考虑更新 Token 和核查 kube-apiserver 的可用性。与此同时,务必选用受支持范围内的容器引擎版本来规避潜在冲突风险。 ```python # 示例 Python 脚本用于自动化部分诊断过程 import os def check_api_server(master_ip): command = f"curl https://{master_ip}:6443/version --cacert /etc/kubernetes/pki/ca.crt" result = os.system(command) if result == 0: print("API Server is reachable.") else: print("Failed to connect to API Server.") check_api_server("<Your_Master_IP>") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彭宇栋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值