Problem Description
Environment: ubuntu18.04 LTS
Phenomenon: After installing kubernetes according to the steps, it starts normally and all commands can be used normally. After the server restarts, the error message when executing the command is as follows:
sudo kubectl get nodes
The connection to the server 127.0.0.1:6443 was refused - did you
specify the right host or port?
Resolution process
- Troubleshoot firewall settings
Check whether the port is open
telnet 127.0.0.1 6443
If you can't connect, you can turn off the firewall
sudo ufw disable
Restart kubernetes
systemctl start kubelet
- Swap partition
Check whether the swap partition is started. If the following content is displayed, the swap partition is enabled
sudo swapon --show
NAME TYPE SIZE USED PRIO
/swap.img file 1.9G 4.5M -2
Close swap partition
sudo swapoff -a
Restart kubernetes and it starts normally
systemctl start kubelet
Completely delete the swap partition
vi /etc/fstab
Delete the following lines in the file:
/swap.img none swap sw 0 0
Restart the computer and kubernetes can automatically start normally.