The connection to the server <host>:6443 was refused - did you specify the right host or port?

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.

  1. The Kubeconfig environmental variable is probably not set.
    export KUBECONFIG=/etc/kubernetes/admin.conf or $HOME/.kube/config
  2. 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
  3. 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. :slight_smile:
  4. 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
  5. 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

  1. 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
5 Likes