kubeadm Join Cluster Error
背景
在 master
机器中使用 one-ansible
安装 k8s
集群。最终发现原因是 kubernetes.foobar.local
这个域名连不上,在新的节点上加上 host
重新执行 kubeadm join
就好了。
错误日志
bash
kubeadm join kubernetes.foobar.local:6443 --token molqef.zcb8h6z6i59wxdvf --discovery-token-ca-cert-hash sha256:c146d7fb88ecc7e41389d7b2c9afdc61f59482f2294846199e09c09d84da676f
TASK [k8s-v1.26 : 加入集群] *****************************************************************************************************************************************************************************************************************************************************************************************************
fatal: [192.168.48.14]: FAILED! => {
"changed": true,
"cmd": [
"kubeadm",
"join",
"kubernetes.foobar.local:6443",
"--token",
"molqef.zcb8h6z6i59wxdvf",
"--discovery-token-ca-cert-hash",
"sha256:c146d7fb88ecc7e41389d7b2c9afdc61f59482f2294846199e09c09d84da676f"
],
"delta": "0:05:00.106883",
"end": "2025-04-16 15:51:38.651855",
"rc": 1,
"start": "2025-04-16 15:46:38.544972"
}
STDOUT:
[preflight] Running pre-flight checks
STDERR:
[WARNING FileExisting-socat]: socat not found in system path
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 "molqef"
To see the stack trace of this error execute with --v=5 or higher
MSG:
non-zero return code
PLAY RECAP ******************************************************************************************************************************************************************************************************************************************************************************************************************
192.168.48.13 : ok=9 changed=3 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
192.168.48.14 : ok=76 changed=31 unreachable=0 failed=1 skipped=23 rescued=0 ignored=4
FATA[0357] exec failed with exit code 2
关键错误
bash
couldn't validate the identity of the API Server: could not find a JWS signature in the cluster-info ConfigMap for token ID "molqef"
解决方案 ChatGPT
这个错误表明你的 kubeadm join
命令在执行 preflight 阶段失败了,具体原因如下:
错误核心信息:
bash
couldn't validate the identity of the API Server: could not find a JWS signature in the cluster-info ConfigMap for token ID "xir402"
意思是集群的控制节点无法识别这个 token,也就是:
- token
xir402.cwffbdv3zw89cnpa
可能已经 过期 - 或者控制平面节点(kubernetes.foobar.local:6443)上的
cluster-info
ConfigMap 不完整 或 没有 JWS 签名
解决方案步骤:
1. 重新生成有效的 join token 和 hash
在控制节点上重新生成:
bash
kubeadm token create --print-join-command
示例输出:
bash
kubeadm join kubernetes.foobar.local:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
复制上面这条命令,并在新的节点上执行。
2. 确认控制节点的 API server 正常
确保你能从工作节点 ping 通控制节点:
bash
ping kubernetes.foobar.local
如果 ping 不通,请确认 DNS 是否配置正确,或者可以临时将主机名加入 /etc/hosts
:
txt
192.168.x.x kubernetes.foobar.local
3. 缺少 socat 警告(非致命)
bash
[WARNING FileExisting-socat]: socat not found in system path
虽然这不是阻止 join 的原因,但建议你安装它:
bash
sudo apt install socat # Ubuntu/Debian
sudo yum install socat # CentOS/RHEL
小结
重新生成 token 是关键。执行:
bash
kubeadm token create --print-join-command
然后再试一遍新命令加入。如果还是失败,可以加上 --v=5
看更详细日志:
bash
kubeadm join ... --v=5