Hi there, if you are still having this issue as I did, there are quite a few things that could be wrong. Ensure swap is off definitely as advised by other comments. Other interesting causes from my sujjourn include.
- The Kubeconfig environmental variable is probably not set.
export KUBECONFIG=/etc/kubernetes/admin.conf or $HOME/.kube/config - The user’s $HOME directory has no .kube/config file.
If you don’t have a .kube or config file
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf HOME/.kube/config sudo chown (id -u):$(id -g) $HOME/.kube/config
Alternatively you can also export KUBECONFIG variable like this:
export KUBECONFIG=$HOME/.kube/config - The server/port configured in the config file above is wrong.
Is it the same as the IP/hostname of the master server? if not did you copy it? You might
want to fix that.
By the way you can get the hostname by issueing the hostname command on your cli. or
ifconfig for the ip. - Kubelet service may be down. This may be due to the fact that swap is enabled.
sudo swapoff -a
To make it permanent go to /etc/fstab
sudo -i
swapoff -a
exit
strace -eopenat kubectl version
sudo systemctl restart kubelet.service - Docker service may be down, hence the kubeapi pod isn’t running
sudo systemctl start docker
sudo systemctl start kubelet
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown (id -u):(id -g) $HOME/.kube/config
- Firewalls may be blocking the access
sudo systemctl status firewalld #redhat centos
sudo systemctl stop firewalld #redhat, centos
sudo ufw status verbose #ubuntu
sudo ufw disable #ubuntu