问题现象
部署完master节点以后,执行kubectl get cs命令来检测组件的运行状态时,报如下错误:
[root@k8s-master yum.repos.d]# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME STATUS MESSAGE ERROR
scheduler Unhealthy Get "http://127.0.0.1:10251/healthz": dial tcp 127.0.0.1:10251: connect: connection refused
controller-manager Unhealthy Get "http://127.0.0.1:10252/healthz": dial tcp 127.0.0.1:10252: connect: connection refused
etcd-0 Healthy {"health":"true"}
[root@k8s-master yum.repos.d]# wget http://127.0.0.1:10251/healthz
--2020-11-14 00:10:51-- http://127.0.0.1:10251/healthz
Connecting to 127.0.0.1:10251... failed: Connection refused.
解决分析
出现这种情况,是/etc/kubernetes/manifests/下的kube-controller-manager.yaml和kube-scheduler.yaml设置的默认端口是0导致的,解决方式是注释掉对应的port即可,操作如下:
[root@k8s-master manifests]# ls
etcd.yaml kube-apiserver.yaml kube-controller-manager.yaml kube-scheduler.yaml
[root@k8s-master manifests]# pwd
/etc/kubernetes/manifests
[root@k8s-master manifests]#
kube-controller-manager.yaml文件修改:注释掉27行,- --port=0
kube-scheduler.yaml配置修改:注释掉19行,- --port=0
然后在master节点上重启kubelet,systemctl restart kubelet.service,然后重新查看就正常了
[root@k8s-master manifests]# vim kube-controller-manager.yaml
[root@k8s-master manifests]# vim kube-scheduler.yaml
[root@k8s-master manifests]# vim kube-controller-manager.yaml
[root@k8s-master manifests]# systemctl restart kubelet.service
[root@k8s-master manifests]# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}