1,问题描述
(1)在安装配置好 Kubernetes 后,正常情况下服务器关机重启,kubelet 也会自动启动的。但最近配置的一台服务器重启后,输入命令 kubectl get nodes 查看节点报如下错误:
The connection to the server 192.168.60.128:6443 was refused - did you specify the right host or port?
(2)输入 systemctl status kubelet 命令查看 kubelet 的情况,发现 kubelet 确实没有启动:
ube-apiserver.service - Kubernetes API Server
Loaded: loaded (/usr/lib/systemd/system/kube-apiserver.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Mon 2019-03-18 14:55:11 CST; 9min ago
Docs: https://github.com/kubernetes/kubernetes
Process: 6446 ExecStart=/opt/kubernetes/bin/kube-apiserver $KUBE_APISERVER_OPTS (code=exited, status=1/FAILURE)
Main PID: 6446 (code=exited, status=1/FAILURE) Mar 18 14:55:11 localhost.localdomain kube-apiserver[6446]: --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
Mar 18 14:55:11 localhost.localdomain kube-apiserver[6446]: --watch-cache Enable watch caching in the apiserver (default true)
Mar 18 14:55:11 localhost.localdomain kube-apiserver[6446]: --watch-cache-sizes strings List of watch cache sizes for every resource (pods, nodes, etc.), comma sepa...ber. It take
Mar 18 14:55:11 localhost.localdomain kube-apiserver[6446]: error: failed to create listener: failed to listen on 192.168.60.128:6443: listen tcp 192.168.247.211:6443: bind: cannot assign requested address
Mar 18 14:55:11 master systemd[1]: kube-apiserver.service holdoff time over, scheduling restart.
Mar 18 14:55:11 master systemd[1]: Stopped Kubernetes API Server.
Mar 18 14:55:11 master systemd[1]: start request repeated too quickly for kube-apiserver.service
Mar 18 14:55:11 master systemd[1]: Failed to start Kubernetes API Server.
Mar 18 14:55:11 master systemd[1]: Unit kube-apiserver.service entered failed state.
Mar 18 14:55:11 master systemd[1]: kube-apiserver.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
2,问题原因
由于 K8s 必须保持全程关闭交换内存,之前我安装是只是使用 swapoff -a 命令暂时关闭 swap。而机器重启后,swap 还是会自动启用,从而导致 kubelet 无法启动。
3,解决办法
(1)首先执行如下命令关闭 swap。
swapoff -a
(2)接着编辑 /etc/fstab 文件。
vi /etc/fstab
(3)将 /dev/mapper/centos-swap swap swap default 0 0 这一行前面加个 # 号将其注释掉。
(4) 编辑完毕后保存退出。这样机器重启后 kubelet 也可以正常自动启动了。