问题场景:
本地测试由于之前安装过K8S今天重启无法使用了,于是重新安装了一下,子节点加入主节点报错:
I0808 23:13:04.299356 19180 round_trippers.go:466] curl -v -XGET -H "Accept: application/json, */*" -H "User-Agent: kubeadm/v1.24.9 (linux/amd64) kubernetes/9710807" 'https://192.168.1.100:6443/api/v1/nodes/node1?timeout=10s'
I0808 23:13:04.300840 19180 round_trippers.go:553] GET https://192.168.1.100:6443/api/v1/nodes/node1?timeout=10s 401 Unauthorized in 1 milliseconds
I0808 23:13:04.300854 19180 round_trippers.go:570] HTTP Statistics: GetConnection 0 ms ServerProcessing 1 ms Duration 1 ms
I0808 23:13:04.300860 19180 round_trippers.go:577] Response Headers:
I0808 23:13:04.300866 19180 round_trippers.go:580] Audit-Id: 1c5934bb-82ed-4955-9499-84ec4397a8f0
I0808 23:13:04.300871 19180 round_trippers.go:580] Cache-Control: no-cache, private
I0808 23:13:04.300876 19180 round_trippers.go:580] Content-Type: application/json
I0808 23:13:04.300881 19180 round_trippers.go:580] Content-Length: 129
I0808 23:13:04.300886 19180 round_trippers.go:580] Date: Thu, 08 Aug 2024 15:13:04 GMT
I0808 23:13:04.300902 19180 request.go:1154] Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401}
问题解决办法:
先说一下原因:是之前加入过,有一些残留文件但是删除了还是没有删除干净。那就需要reset一下,执行命令即可:
[root@node1 ~]# kubeadm reset -f
此时再次join没有问题成功。
补充:
1、调试技巧还是在join下增加一个输出细节级别 --v 方便调试:
[root@node1 ~]# kubeadm join 192.168.1.100:6443 --token mk6uf1.eef01he2iqok22tm --discovery-token-ca-cert-hash sha256:e0ad6e494a6c6b192b88f136a96c421e28d63b235b54091bf04faa5db36aa609 --v=10
2、一键清理并reset,之心过后直接可以运行join:
[root@node1 ~]# rm -rf /root/.kube && rm -rf /etc/cni/net.d && rm -rf /etc/kubernetes/* && kill -9 $(lsof -i:10250 |awk 'NR>1 {print $2}') && kubeadm reset -f