目录
1.环境目录
2.问题现象
3.问题定位
4.问题解决
环境介绍
# k8s集群环境如下:
[root@k8s-master][~]
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.0", GitCommit:"xxx", GitTreeState:"clean", BuildDate:"xxx", GoVersion:"go1.17.3", Compiler:"gc", Platform:"linux/amd64"}
[root@k8s-master][~]
$kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 559d v1.23.0
k8s-node1 Ready <none> 559d v1.23.0
k8s-node2 Ready <none> 559d v1.23.0
# 系统环境信息
[root@k8s-master][~]
$cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
问题现象
#1 在master节点查看node节点信息的时候报NotReady
[root@k8s-master][~]
$kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 559d v1.23.0
k8s-node1 Ready <none> 559d v1.23.0
k8s-node2 NotReady <none> 559d v1.23.0
#2 登录k8s-node2,查看kubelet状态,处于restarting状态
[root@k8s-node2][~]
$systemctl status kubelet
#3 查看日志,出现报错
[root@k8s-node2][~]
$journalctl -fu kubelet
.........
Streaming server stopped unexpectedly" err="listen tcp [::1]:0: bind: cannot assign requested address
.........
问题定位
#1 初步判定
通过报错信息 [::1]:0: bind 可以判断回环地址有问题
#2 查看hosts配置信息,发现没配置本地解析信息
[root@k8s-node2][~]
$cat /etc/hosts
xx.xx.xx.xx k8s-master
xx.xx.xx.xx k8s-node1
xx.xx.xx.xx k8s-node2
问题解决
#问题原因已找到,接下来就是解决问题
#1 在hosts添加以下信息
[root@k8s-node2][~]
$vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#2 重启kubelet
[root@k8s-node2][~]
$systemctl restart kubelet
#3 查看kubelet状态,已经处于running
[root@k8s-node2][~]
$systemctl status kubelet
#4 登录master节点查看node信息,已经变成ready了
[root@k8s-master][~]
$kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 559d v1.23.0
k8s-node1 Ready <none> 559d v1.23.0
k8s-node2 Ready <none> 559d v1.23.0
#5 查看是否还有异常pod,通过命令查看已经无异常pod了
[root@k8s-master][~]
$kubectl get pod -A |grep -v Running
至此问题得以解决。