问题信息
1.kubectl命令查看信息报如下问题(系统版本为 Ubuntu-18-04):
root@k8s-node2:~# kubectl get node
The connection to the server localhost:8080 was refused - did you specify the right host or port?
2.查看kubelet状态发现为未启动状态
root@k8s-node2:~# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: activating (auto-restart) (Result: exit-code) since Mon 2022-01-10 20:54:05 CST; 2s ago
3.重启kubelet后无效,仍为未启动状态
4.关闭swap后,重启成功。
root@k8s-node1:~# swapoff -a
root@k8s-node1:~# free
total used free shared buff/cache available
Mem: 2017444 279420 151024 860 1587000 1551172
Swap: 0 0 0
root@k8s-node1:~# systemctl start kubelet
root@k8s-node1:~# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since Mon 2022-01-10 20:32:25 CST; 23s ago
总结
kubelet启动时需要关闭swap交换空间。
永久关闭swap方法为将/etc/fstab 文件中/swap开头的行注释掉即可。